[英]Change value in object within array in array with Ember.js 1.13
在我的應用程序中,我有一個結構,其中對象包含在數組中的數組中。 這些對象稱為AND規則,帶有對象的數組稱為OR規則。 結構如下:
matching: [
[ // OR rule
{ // AND rule
name: "rule #1.1",
value: "test"
},
{ // AND rule
name: "rule #1.2",
value: "test B"
}
],
[ // OR rule
{ // AND rule
name: "rule #2.1",
value: "test C"
}
]
]
當我嘗試更改其中一個值時,Ember會更改所有值。 例如,如果我將規則#1.2的值更改為“測試值”,則規則#1.1和規則#2.1的值也會更改為“測試值”。 我使用以下代碼來設置值:
setValue (andIndex, orIndex, value) {
var orRule = this.get('matching').objectAt(orIndex);
var andRule = orRule.objectAt(andIndex);
Ember.set(andRule, 'value', value.target.value);
}
我更改值的模板如下所示:
{{#each matching as |orRule orIndex|}}
{{#each orRule as |andRule andIndex|}}
<input type="text" onkeyup={{action 'setValue' andIndex orIndex value=value}}>
{{/each}}
{{/each}}
我的問題是:我只想更改我更改的一個值。 我該怎么做呢? 注意:我使用Ember.JS 1.13。
您無需采取任何行動。 只需在input
助手中設置值
{{#each matching as |orRule orIndex|}}
{{#each orRule as |andRule andIndex|}}
{{input value=andRule.value}}
{{/each}}
{{/each}}
更新
請檢查該出來。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.