gpt4 book ai didi

arrays - Ember.js - 将数组绑定(bind)到表/网格中的单选按钮,当用户选择网格/表中的单选按钮时更新相同的数组

转载 作者:行者123 更新时间:2023-12-05 07:59:24 27 4
gpt4 key购买 nike

following is my code: when i click any row in grid /table i should be able to update the array elements back in the array

<script type="text/x-handlebars" data-template-name="application">
<table border="1">
{{#each content}}
<tr><td>{{name}} {{view Ember.RadioButton name="selectionTest" selectionBinding="isSelected" valueBinding="name"}}</td></tr>
{{/each}}
</table>
<div>Is Selected: {{isSelected}}</div>
</script>


console.clear();
window.App = Ember.Application.create({});

Ember.RadioButton = Ember.View.extend({
tagName: "input",
type: "radio",
arrBinding: 'App.ApplicationController.content',
attributeBindings: ["name", "type", "value", "checked:checked:"],
click: function () {
this.set("selection", this.$().val())
alert(this.$().val());
alert(arrBinding);
},
checked: function () {
return this.get("value") == this.get("selection");

}.property()
});

here i have declared the array elements

App.ApplicationController = Ember.ObjectController.extend({
isSelected: 'Ashish',

content:[
{
name: 'Ashish',
selected: false
},
{
name: 'Eben',
selected: false
},
{
name: 'Ronald',
selected: false
},
{
name: 'Jamie',
selected: false
}
]
});

这是 jsfiddle:http://jsfiddle.net/CM6fK/169/

最佳答案

不完全确定你在问什么,但首先你需要将你的 selectionBinding 绑定(bind)到你的 Controller :

<script type="text/x-handlebars" data-template-name="application">
<table border="1">
{{#each content}}
<tr><td>{{name}} {{view Ember.RadioButton name="selectionTest" selectionBinding=this.controller.isSelected valueBinding="name"}}</td></tr>
{{/each}}
</table>
<div>Is Selected: {{isSelected}}</div>
</script>

至于另一点。我认为你需要改变:

    alert(arrBinding);

    alert(this.arrBinding);

虽然我真的不确定你想在那里实现什么。

这是一个更新的 jsfiddle:http://jsfiddle.net/CM6fK/172/

关于arrays - Ember.js - 将数组绑定(bind)到表/网格中的单选按钮,当用户选择网格/表中的单选按钮时更新相同的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21911205/

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