我有一种情况,当用户按下刷新按钮时,我想要reload模型。我之前使用Ember-Model实现了此功能,但是,我们最近将其移至Ember-Data,并且在试图从模型类运行任何method时收到错误消息。任何帮助,将不胜感激。Ember.js在运行类方法时抛出“没有方法”错误
单击按钮时错误:
Uncaught TypeError: Object [object Object] has no method 'reload'
应用程序的结构:
App.ApplicationAdapter = DS.DjangoRESTAdapter.extend({
namespace: 'api/1'
});
App.SomeRoute = Ember.Route.extend({
model: function() {
return this.store.find('publishable');
},
});
App.SomeModel = DS.Model.extend({
title: attr(),
description: attr(),
authors: hasMany('author', { async: true }),
category: belongsTo('page', { async: true }),
published: attr(),
publish_from: attr(),
slug: attr(),
contentType: attr(),
});
App.SomeController = Ember.ArrayController.extend({
actions : {
reload: function(model) {
model.reload();
}
}
});
<div>
<span {{action reload model}} class="btn"></span>
</div>
当我控制器上的动作内登录this.get('model')
。我收到以下内容:
Class {type: function, content: (...), store: Class, isLoaded: true, isUpdating: false…}
__ember1390344611587: "ember592"
__ember1390344611587_meta: Object
_super: undefined
arrangedContent: (...)
content: (...)
get content: function() {
set content: function (value) {
isLoaded: true
isUpdating: false
store: Class
toString: function() { return ret; }
type: App.Publishable
__proto__: Object
很可能您所获得的对象不是DS.Model的一个实例。你应该调试你的代码来找出它的真实性。作为一个侧面说明,你的关系是异步的,所以试图“获取”它们会返回一个承诺,而不是一个模型。这可能是你的问题。 – GJK
它也可以帮助你使用'Ember.inspect(模型)'来查看你正在处理的对象。 –