【问题标题】:Binding checked checkboxes to array attribute in Ember.js将选中的复选框绑定到 Ember.js 中的数组属性
【发布时间】:2014-07-22 15:16:37
【问题描述】:

我有一个带有一些输入字段和复选框的表单。路线如下所示:

SharedContentNewRoute = Ember.Route.extend
  setupController: (controller) ->
    content = @modelFor("content")
    controller.set('content', @store.createRecord('shared_content'))
    controller.set('handles', @store.find("handle"))

shared_content 模型除了其他属性外,还有一个 handle_ids 数组属性,该属性需要填充选中复选框的 id。用于填充复选框(可用句柄)的模板在 shared_content/new 模板中定义:

...
{{#each handles}}
  <div class="checkbox">
    {{input type="checkbox" id=id}}
    <label {{bind-attr for="id"}}>{{data.name}}</label>
  </div>
{{/each}}
...

问题是我需要在模型保存之前获取选中的复选框 id 并将它们放入 shared_content 模型(这是此模板的模型)的 handle_ids 属性中。这种绑定有很好的解决方案吗?

【问题讨论】:

  • 你发现了吗?

标签: javascript checkbox ember.js


【解决方案1】:

它需要这样的东西才能工作:)

{{#view class="checkbox" tagName="span"}}
  {{input type="checkbox" checked=isSelected viewName="checkboxView"}}
     <label class="checkbox" {{bind-attr for="view.checkboxView.elementId"}}>
         {{data.name}}
      </label>
{{/view}}

【讨论】:

    【解决方案2】:

    看看这个

    http://emberjs.com/guides/getting-started/show-when-all-todos-are-complete/ http://emberjs.com/guides/getting-started/toggle-todo-editing-state/

    这可能可以帮助您,当检查复选框时,可以在选中复选框后执行功能,可以在控制器/路由器上创建一个对象,然后保存其中的复选框信息

    【讨论】:

    • 这个答案非常无用。您知道解决方案是什么吗?如果知道,您能否详细说明?
    • 两个链接现在都是 404
    猜你喜欢
    • 2014-11-11
    • 2017-08-21
    • 2012-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多