[英]Model reloading with Ember Data
I'm trying to poll for more data using the documented model.reload() function 我正在尝试使用记录的model.reload()函数轮询更多数据
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? 有没有更好的方法来做到这一点,似乎我无法以这种方式从路线访问模型?
Here is the router 这是路由器
App.Router.map(function() {
this.route('video', { path: '/videos/:video_id' });
});
Here is the route 这是路线
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!');
}
}
});
Here is the model 这是模型
App.Video = DS.Model.extend({
title: DS.attr('string'),
status: DS.attr('string')
});
And the templates 和模板
<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>
I've made a jsbin of the issue here: 我在这里写了一个问题的jsbin:
http://jsbin.com/wofaj/13/edit?html,js,output http://jsbin.com/wofaj/13/edit?html,js,output
I really can't understand why the reload gives me this error. 我真的不明白为什么重装给我这个错误。 Any advice would be much appreciated.
任何建议将不胜感激。
Thanks 谢谢
Since model
already exists as a hook on Ember.Route, you cannot get that as a property. 由于
model
已作为Ember.Route上的钩子存在,因此无法将其作为属性。
Instead you can do the following: 相反,您可以执行以下操作:
this.modelFor('video').reload();
Technically you could do this.get('currentModel').reload();
从技术上讲,你可以这样做
this.get('currentModel').reload();
too, but that's undocumented and probably won't be available in the future. 也是如此,但那是没有证件的,将来可能无法使用。
The route model function provides a hook to load your controller data. 路径模型功能提供了一个挂钩来加载控制器数据。 There is a specific section at the ember guide .
在余烬指南中有一个特定的部分。
1) If you want to access your content, it would be like: 1)如果您想访问您的内容,它将是:
reload: function() {
this.controller.get('content');
}
2) reload is a method available of ember-data objects. 2) 重载是一种可用于ember-data对象的方法。 In your example, you are loading a js object ({ id:2, title:"Test video title 2", status:"downloading"}).
在您的示例中,您正在加载一个js对象({id:2,标题:“测试视频标题2”,状态:“下载”})。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.