gpt4 book ai didi

javascript - 在 Ember JS 中选择动态创建的复选框

转载 作者:行者123 更新时间:2023-11-28 00:11:33 25 4
gpt4 key购买 nike

您好,我正在从服务器端模型中提取数据并通过复选框填充它们。如何获取用户对复选框的选择?我知道 this.get('isChecked') 可以获取复选框的值,但是由于将动态填充可变数量的复选框,因此在我的用户案例中如何执行此操作?

注意:我没有使用 Ember 数据,也没有通过从路由器类对服务器 API 的 Ember.$.JSON() 调用来填充模型。

我尝试按照此处给出的示例 Dynamically Create Inputs with Ember (and retrieve their values)在这里 EmberJS - Checkboxes and Getting Values in Controller但他们似乎都不适合我。

品牌模型有一个已检查的 bool 属性,默认情况下选择为 false。

  {{#each brand in model}}

<div class="col-lg-2 col-xs-4">
<div class="brand-select-image-container">
{{input type="checkbox" name=brand.brand_name checked=brand.checked class="brand-select-checkbox" }}

<img src="http://localhost:3000{{brand.img_location}}" class="brand-select-image"/>

</div>
<p class="brand-select-name">{{brand.brand_name}}</p>
</div>

{{/each}}

最佳答案

好吧,我为其他那些很难弄清楚如何使 ember 复选框工作的人修复了这个问题

  this.get('model').forEach(function(item){
console.log(item.checked);
});

关于javascript - 在 Ember JS 中选择动态创建的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30833175/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com