如何使用 ractive 观察多个关键路径?

How can I observe multiple key paths with ractive?

我想根据 docs on ractive observe 观察关键路径的变化。但是,我希望能够同时观察多条路径,例如,给定:

var binding = new Ractive({
  el: '.here',
  data: {
    items: [
      {
        finished: false
      },
      {
        finished: false
      }  
    ]
  },
  template: someTemplate
})

我希望能够做类似的事情:

binding.observe('items.*.finished')

或类似于能够观看数组中任何项目的 finished 属性。

最好的方法是什么?

与您描述的完全一样! http://jsfiddle.net/rich_harris/c3yc848z/

请注意,任何 * 占位符的值都会作为附加参数传递给回调,超出您通常获得的 (newValue, oldValue, keypath) - 因此在这种情况下会有第四个 index 参数。