admin管理员组文章数量:1416074
I have an ember template that loads some JSON data on page load, there are some buttons and when these buttons are clicked I need to make different json calls and update the model.
Everything works fine in this code but the model is not being updated after the action is triggered and the json call is made.
How can I fix it?
App.DatRoute = Ember.Route.extend({
model: function(parms){
return Em.RSVP.hash({
datam : Ember.$.getJSON('URL')
});
},
afterModel: function(){
$(document).attr('title', 'Title');
},
renderTemplate: function() {
this.render();
this.render('fter', { into: 'outlet', outlet: 'fter' });
},
actions :{
action: function(){
return Em.RSVP.hash({
datam : Ember.$.getJSON('URL', {data})
});
}
}
});
Thanks
I have an ember template that loads some JSON data on page load, there are some buttons and when these buttons are clicked I need to make different json calls and update the model.
Everything works fine in this code but the model is not being updated after the action is triggered and the json call is made.
How can I fix it?
App.DatRoute = Ember.Route.extend({
model: function(parms){
return Em.RSVP.hash({
datam : Ember.$.getJSON('URL')
});
},
afterModel: function(){
$(document).attr('title', 'Title');
},
renderTemplate: function() {
this.render();
this.render('fter', { into: 'outlet', outlet: 'fter' });
},
actions :{
action: function(){
return Em.RSVP.hash({
datam : Ember.$.getJSON('URL', {data})
});
}
}
});
Thanks
Share Improve this question asked Nov 9, 2014 at 4:22 rkshrksh 4,05010 gold badges52 silver badges72 bronze badges1 Answer
Reset to default 6Because you're not doing anything that updates the model. Ember does nothing with the return value from an action, be it a promise or otherwise. You need to put the action on the controller and set the model with the data ing back from the ajax call:
action: function() {
var self = this;
Ember.$.getJSON('URL', {data})
.then(function(result) {
self.set('model', result);
});
}
or my style, entirely equivalent
action: function() {
var set = this.set.bind(this, 'model');
Ember.$.getJSON('URL', {data}).then(set);
}
本文标签: javascriptEmber Update model after actionStack Overflow
版权声明:本文标题:javascript - Ember Update model after action - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745163228a2645547.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论