Ember在模型上找不到find()方法

bir*_*ric 5 javascript ember.js

灰烬似乎无法找到findAll()find()我有我的属性模型实现的方法.以下是我得到的错误:

TypeError: App.Property.findAll is not a function
Run Code Online (Sandbox Code Playgroud)

Error: assertion failed: Expected App.Property to implement `find` for use in 'root.property' `deserialize`. Please implement the `find` method or overwrite `deserialize`.
Run Code Online (Sandbox Code Playgroud)

我的路由器设置如下:

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);
            },
        }),
    })
});
Run Code Online (Sandbox Code Playgroud)

这是我的模型:

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() {
        // ...
    }
});
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?这些方法是应该使用Property模型还是应该去其他地方?我应该覆盖deserialize()方法而不是使用find()?但即使我使用该解决方法findAll()仍然无法工作,我仍然会得到第一个错误.

谢谢你的帮助.

lou*_*uio 8

findfindAll方法应该声明中reopenClass,没有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() {
        // ...
    }
});
Run Code Online (Sandbox Code Playgroud)