2

我如何找到其名称等于某物的相关模型?我试过: this.get('content').findProperty('name', name),但它似乎不起作用。我想如果我的枚举中没有塞满模型,它会起作用......

4

1 回答 1

2

在您的实例上使用findProperty/ ,请参阅http://jsfiddle.net/pangratz666/kPmHr/findEmber.ArrayController

App.peopleController = Ember.ArrayController.create({
    content: [
        App.Person.create({ name: 'Adam' }),
        App.Person.create({ name: 'John' }),
        App.Person.create({ name: 'Adam' })
    ],

    findByName: function(name) {
        var found = this.findProperty('name', name);
        console.log('found model %@'.fmt(found));
    }
});

App.peopleController.findByName('Adam');​
于 2012-06-22T10:23:01.477 回答