如何找到名称相等的相关模型?我试过了this.get('content').findProperty('name', name)
,但它似乎不起作用。我想如果我的可枚举不是满满的模型那就行了......
答案 0 :(得分:2)
在findProperty
个实例上使用find
/ Ember.ArrayController
,请参阅http://jsfiddle.net/pangratz666/kPmHr/:
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');