【问题标题】:bind helper like get & mut? How to bind input to dynamically specified property?像 get & mut 这样的绑定助手?如何将输入绑定到动态指定的属性?
【发布时间】:2016-08-20 01:00:41
【问题描述】:

我可以使用input 助手来切换item 的布尔属性,如下所示:

  {{input type="checkbox" checked=item.isSelected}}

如果我想要一个显示项目属性的模板,但属性名称是动态传入的,我可以使用 get 帮助器。

{{get item propertyName}}

我可以结合这两种方法将复选框checked 属性绑定到动态指定的属性吗?

  {{input type="checkbox" checked=(?bind? item propertyName)}}

目前我正在使用下面的解决方法,但这对我来说似乎不合适(错了吗?)。

  {{input type="checkbox"
  checked=(get item propertyName)
  action=(toggle propertyName item) on="change"}}

【问题讨论】:

  • 你可以像下面这样结合 mut 和 get helper {{input type="checkbox" checked=(mut (get item propertyName))}}

标签: ember.js


【解决方案1】:

是的。您可以组合 getmut 助手。 {{get}} helper 也可以尊重可变值本身。示例Ember-Twiddle

{{input type="checkbox" checked=(mut (get item propertyName))}}

获取 Helper 参考:http://emberjs.com/api/classes/Ember.Templates.helpers.html#method_get

【讨论】:

    猜你喜欢
    • 2021-05-21
    • 1970-01-01
    • 1970-01-01
    • 2021-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-08
    • 1970-01-01
    相关资源
    最近更新 更多