Chr*_*ris 8 javascript ember.js ember-data
我正在尝试使用记录的model.reload()函数轮询更多数据
App.ModelViewRoute = Ember.Route.extend({
actions: {
reload: function() {
this.get('model').reload();
}
}
});
Run Code Online (Sandbox Code Playgroud)
但是我收到一条错误消息说......
undefined is not a function TypeError: undefined is not a function
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来做到这一点,似乎我无法以这种方式从路线访问模型?
这是路由器
App.Router.map(function() {
this.route('video', { path: '/videos/:video_id' });
});
Run Code Online (Sandbox Code Playgroud)
这是路线
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!');
}
}
});
Run Code Online (Sandbox Code Playgroud)
这是模型
App.Video = DS.Model.extend({
title: DS.attr('string'),
status: DS.attr('string')
});
Run Code Online (Sandbox Code Playgroud)
和模板
<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>
Run Code Online (Sandbox Code Playgroud)
我在这里写了一个问题的jsbin:
http://jsbin.com/wofaj/13/edit?html,js,output
我真的不明白为什么重装给我这个错误.任何建议将不胜感激.
谢谢
ant*_*ore 14
refresh路线的方法会做你想要的
App.VideoRoute = Ember.Route.extend({
model: function(params) {
return this.store.find('video', params.video_id);
},
actions: {
reloadModel: function() {
this.refresh()
}
}
});
Run Code Online (Sandbox Code Playgroud)
小智 13
由于model已经作为Ember.Route上的钩子存在,因此无法将其作为属性获取.
相反,您可以执行以下操作:
this.modelFor('video').reload();
Run Code Online (Sandbox Code Playgroud)
从技术上讲,你也可以这样做this.get('currentModel').reload();,但那是没有文件记录的,将来可能无法使用.
| 归档时间: |
|
| 查看次数: |
25877 次 |
| 最近记录: |