ember.js - Ember.RSVP.All error Array Methods must be provided an Array -
cross-posted discuss.emberjs.com
i'm trying save model upon successful save save additional models related intial model. these in standard input fields can't/don't know how bind ed i'm using standard jquery selectors find inputs , save models. models saving ember.rsvp.all
hitting reject
callback due array methods must provided array
error. i'm not sure i'm supposed providing array...
i've inspected various elements along way , var promises
array of promises expected. thing can think of results
value beingness passed resolve callback supposed array? if that's case i'm not sure how create array other maybe passing in ember.a()
or []
here relevant code in controller.
submit: function () { var self = this; var partition = this.get('model'); var isnew = division.get('isnew'); if(isnew) { division.setproperties({ vendor: self.get('parentvendor'), vendorcategory: self.get('selectedcategory'), isactive: true, createdby: 1, createddate: moment().format() }); } else { division.setproperties({ vendorcategory: self.get('selectedcategory'), modifiedby: 1, modifieddate: moment().format() }); } division.validate().then(function () { if (division.get('isvalid')) { division.save().then(function(result) { /* bit of hackishness loops through each of attribute input fields, creates new ds.model attribute, saves model, returns resulting promise promises array can processed rsvp.all ensure attributes save properly. */ // map promises array var promises = $('input.attribute').map(function () { var elem = $(this)[0]; var vendortypeattrid = $(elem).attr('data-attribute-id'), attrvalue = $(elem).val(); // create model var model = self.store.createrecord('vendor-division-attribute', { division: result, vendortypeattribute: self.get('categoryattributes').findby('id', vendortypeattrid), value: attrvalue, createdby: 1, createddate: moment().format() }); // homecoming save promise var p = model.save(); homecoming p; }); // create sure promises resolved before continuing ember.rsvp.all(promises).then(function (results) { // worked! maintain calm , move along self.send('closemodal'); var msg = isnew ? division.get('name') + ' created!' : 'changes saved!'; bootstrap.nm.push(msg, 'success'); }).catch(function(reason) { // went wrong - display error if (typeof reason.error !== 'undefined') { // dsp error if (ember.keys(reason.error).length > 0) { error = reason.error[0].message; } else { error = 'an error occured while saving changes'; } } else if (typeof reason.message !== 'undefined') { error = reason.message; } else { error = reason; } console.log(error); bootstrap.nm.push('error saving vendor division: ' + error, 'danger'); }); }, function(reason) { var error; if (typeof reason.error !== 'undefined') { // dsp error if (ember.keys(reason.error).length > 0) { error = reason.error[0].message; } else { error = 'an error occured while saving changes'; } } else if (typeof reason.message !== 'undefined') { error = reason.message; } else { error = reason; } console.log(error); bootstrap.nm.push('error saving vendor division: ' + error, 'danger'); }); } }); }
your promises
array isn't array. jquery returns array-like object, not true array. seek running code in console , you'll see:
var = $('a').map(function() { homecoming 1; }); console.log(array.isarray(a)); console.log(a instanceof array);
luckily, jquery provides nice makearray
function solve problem. after declare promises
, before phone call ember.rsvp.all
, insert line:
promises = $.makearray(promises);
ember.js rsvp.js rsvp-promise
No comments:
Post a Comment