使用 Ember.js 1.13 更改数组中对象中的值

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 的值更改为 "Test value",规则 #1.1 和规则 #2.1 的值也会更改为 "Test value"。我使用以下代码设置值:

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 helper

中设置值
{{#each matching as |orRule orIndex|}}
  {{#each orRule as |andRule andIndex|}}
    {{input value=andRule.value}}
  {{/each}}
{{/each}}

更新

请检查this