【问题标题】:How can I observe multiple key paths with ractive?如何使用 ractive 观察多个关键路径?
【发布时间】:2015-09-28 14:34:26
【问题描述】:

我想观察每个docs on ractive observe 对关键路径的更改。但是,我希望能够同时观察多条路径,例如,给定:

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

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

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

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

最好的方法是什么?

【问题讨论】:

    标签: javascript data-binding ractivejs


    【解决方案1】:

    和你描述的一样! http://jsfiddle.net/rich_harris/c3yc848z/

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

    【讨论】:

    • 哈哈,它就在文档中Any of the keys can be a * character, which is treated as a wildcard.
    猜你喜欢
    • 2016-11-26
    • 1970-01-01
    • 2016-02-23
    • 2022-11-17
    • 2011-03-25
    • 1970-01-01
    • 1970-01-01
    • 2018-10-17
    • 1970-01-01
    相关资源
    最近更新 更多