使用Ember Data进行模型重新加载 [英] Model reloading with Ember Data
问题描述
我正在使用已记录的model.reload()函数来轮询更多数据。
I'm trying to poll for more data using the documented model.reload() function
App.ModelViewRoute = Ember.Route.extend({
actions: {
reload: function() {
this.get('model').reload();
}
}
});
但是我收到一条错误消息说...
But i'm getting an error message saying...
undefined is not a function TypeError: undefined is not a function
有没有更好的方式这样做,似乎我无法以这种方式从路由访问模型?
Is there a better way of doing this, it seems like I cannot access the model in this way from the route?
这里是路由器
App.Router.map(function() {
this.route('video', { path: '/videos/:video_id' });
});
这是路线
App.VideoRoute = Ember.Route.extend({
model: function(params) {
return this.store.find('video', params.video_id);
},
actions: {
reloadModel: function() {
// PROBLEM HERE
// this.get('model').reload();
Ember.Logger.log('reload called!');
}
}
});
这是模型
App.Video = DS.Model.extend({
title: DS.attr('string'),
status: DS.attr('string')
});
模板
<script type="text/x-handlebars" data-template-name="application">
<h1>Testing model reloading</h1>
{{#link-to "video" 1}}view problem{{/link-to}}
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="video">
<h1>Video</h1>
<h2>{{title}}</h2>
{{model.status}}
<p><button {{action 'reloadModel'}}>Reload model</button></p>
</script>
我在这里做了一个jsbin问题:
I've made a jsbin of the issue here:
http://jsbin.com/wofaj/13/edit? html,js,输出
我真的不明白为什么重载给我这个错误。任何建议将不胜感激。
I really can't understand why the reload gives me this error. Any advice would be much appreciated.
谢谢
推荐答案
code> model 已经存在为Ember.Route的钩子,您不能将其作为属性。
Since model
already exists as a hook on Ember.Route, you cannot get that as a property.
相反,您可以以下:
this.modelFor('video').reload();
从技术上讲,您可以执行 this.get('currentModel')。reload );
也是,但这是没有记录的,可能将来不可用。
Technically you could do this.get('currentModel').reload();
too, but that's undocumented and probably won't be available in the future.
这篇关于使用Ember Data进行模型重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!