Javascript 余烬罐';在模型上找不到find()方法
Ember似乎找不到我在属性模型上实现的Javascript 余烬罐';在模型上找不到find()方法,javascript,ember.js,Javascript,Ember.js,Ember似乎找不到我在属性模型上实现的findAll()和find()方法。以下是我得到的错误: TypeError: App.Property.findAll is not a function 及 我的路由器设置如下: App.Router = Ember.Router.extend({ showProperty: Ember.Route.transitionTo('property'), root: Ember.Route.extend({ home:
findAll()
和find()
方法。以下是我得到的错误:
TypeError: App.Property.findAll is not a function
及
我的路由器设置如下:
App.Router = Ember.Router.extend({
showProperty: Ember.Route.transitionTo('property'),
root: Ember.Route.extend({
home: Ember.Route.extend({
route: '/',
connectOutlets: function(router) {
router.get('applicationController').connectOutlet('home', App.Property.findAll());
}
}),
property: Ember.Route.extend({
route: '/property/:property_id',
connectOutlets: function(router, property) {
router.get('applicationController').connectOutlet('property', property);
},
}),
})
});
这是我的模型:
App.Property = Ember.Object.extend({
id: null,
address: null,
address_2: null,
city: null,
state: null,
zip_code: null,
created_at: new Date(0),
updated_at: new Date(0),
find: function() {
// ...
},
findAll: function() {
// ...
}
});
我做错了什么?这些方法应该放在属性模型上还是放在其他地方?我应该重写反序列化()
方法而不是使用find()
?但即使我使用该变通方法findAll()
谢谢你的帮助 应该在researclass
中声明find
和findAll
方法,而不是在extend
中声明,因为您希望定义类方法,而不是实例方法。
例如:
App.Property = Ember.Object.extend({
id: null,
address: null,
address_2: null,
city: null,
state: null,
zip_code: null,
created_at: new Date(0),
updated_at: new Date(0)
});
App.Property.reopenClass({
find: function() {
// ...
},
findAll: function() {
// ...
}
});
App.Property = Ember.Object.extend({
id: null,
address: null,
address_2: null,
city: null,
state: null,
zip_code: null,
created_at: new Date(0),
updated_at: new Date(0)
});
App.Property.reopenClass({
find: function() {
// ...
},
findAll: function() {
// ...
}
});