displayOrder as object attribute
This is how it looks before the POST request. I am trying to save the displayOrder attribute to the model so that it is included in the payload. But it ends up being null and never receives the data from the attribute object either. Everything else goes into the payload fine.
selectWidget: function(widget) {
debugger
var selectedWidget = this.get('selectedWidgets').findProperty('id', widget.id);
if(selectedWidget){
this.get('selectedWidgets').removeObject(selectedWidget);
} else {
if(this.get('selectedWidgets').length == 0) {
widget.set('displayOrder', 1);
} else {
widget.set('displayOrder', (this.get('selectedWidgets').length + 1));
}
widget.set('checked', true);
this.get('selectedWidgets').addObject(widget);
}
},
Here I am setting the displayOrder. The set method only adds it as an attribute and not as part of ember _data.
save: function() {
var self = this;
debugger
this.get('rfm_widgets').addObjects(this.get('selectedWidgets'));
this.set('account_id', this.get('currentUser.account.id'));
if(this.get('model').validate()) {
this.get('model')
.save().then(
function success(response){
self.get('selectedWidgets').clear();
self.get('availableWidgets').forEach(function(widget){
widget.checked = false;
});
self.transitionToRoute('iknow');
self.get('flash').success(_('<q>%@1<q> profile successfully added'), response.get('name'));
},
function error(err){
Ember.Logger.error('error occured');
}
);
}
},
This is the save method above where I insert the objects into the model. At this point the displayOrder does not go inside.
Profile model:
rfm_widgets: DS.hasMany('rfm_widget', {defaultValue: []}),
Widget model:
name: DS.attr(),
description: DS.attr(),
displayOrder: DS.attr(),
is_active: DS.attr(),
account: DS.belongsTo('account'),
created_by_id: DS.attr(),
created_at: DS.attr(),
updated_by_id: DS.attr(),
updated_at: DS.attr(),
I'm new to Ember and have struggled with this issue for days and have found looked all over the net. Happy to provide more code or description of issue. Many thanks in advance!
Aucun commentaire:
Enregistrer un commentaire