我有以下对象结构,我需要获取特定的标题值,然后将其设置为新值。我知道一旦你进入一个嵌套对象,你就会失去 Ember 对象的 .get() 和 .set() 方法。尝试以标准 JavaScript 方式设置值导致错误提示必须使用 ember.set()。
当它观察到对 App.job.code 的更改但我得到断言失败时,这就是我想要发生的事情:您必须使用 Ember.set() 来访问此属性([object Object])
updateTitle: function(){
App.jobs.jobProducts[0].allocations[0].allocationTitle = "test2";
}.observes("App.job.code")
如何最好地实现这一目标?谢谢
App.jobs = [
{
id: 0,
jobTitle: "This is the only job",
jobProducts: [
{
id: 0,
productTitle: "Product 1",
allocations:[
{
id: 0,
allocationTitle: "Allocation 1",
deliverys:[
{
id: 0,
deliveryTitle: "Delivery 1"
},
{
id: 1,
deliveryTitle: "Delivery 2"
}
]
},
{
id: 1,
allocationTitle: "Allocation 2",
deliverys:[
{
id: 0,
deliveryTitle: "Delivery 3"
},
{
id: 1,
deliveryTitle: "Delivery 4"
}
]
}
]
},
{
id: 1,
productTitle: "Product 2",
allocations:[
{
id: 0,
allocationTitle: "Allocation 3",
deliverys:[
{
id: 0,
deliveryTitle: "Delivery 5"
},
{
id: 1,
deliveryTitle: "Delivery 6"
}
]
},
{
id: 1,
allocationTitle: "Allocation 4",
deliverys:[
{
id: 0,
deliveryTitle: "Delivery 7"
},
{
id: 1,
deliveryTitle: "Delivery 8"
}
]
}
]
}
]
}
];