考虑以下数组
siteid address
123 1 New Street, New Town, Newvile
456 2 Elm Road, New York, New York
我无法为数组内的属性添加别名,如下所述
auth: [{
username: "",
password: "",
},
{
username: "",
password: "",
}
]
如何实现这一目标?
答案 0 :(得分:1)
您可以使用firstObject
返回第一个元素
和objectAt()
获取数组的特定元素
我担心后者不适用于computed.alias()
auth: [{
username: "firstName",
password: "",
},
{
username: "maxmustermann",
password: "",
}
],
defaultUsername: Ember.computed.alias('auth.firstObject.username'),
username: Ember.computed('auth', function() {
return this.get('auth').objectAt(1).username;
}),