选择第一个单选按钮敲门js

时间:2015-12-16 23:16:28

标签: javascript knockout.js

请考虑以下事项:

self.container = ko.observableArray([{name: 'hello', amount: [{item: name, key: '4', selected: 0}, {item: 'name', key: 2, selected: '1'}]}, {name: 'hello', amount: [{item: name, key: 10, selected: 0}, {item: name, key: 8, selected: '1'}]}]);
self.amountSelected = ko.observableArray();

如果我这样做:

<div data-bind="foreach: container">
  <div data-bind="foreach: amount">
    <input type="radio" name="radio-selection-name" data-bind="attr: {value: key}, checked: $root.amountSelected()[$index()] || selected" />
  </div>
</div>

这是有效的,不起作用的是注意如何选择其中一个金额,因为它有一个'1'

如何说,选择当前选定的项目或使用此对象的所选项目?

如果对象上的所选属性为“1”,是否有办法为该索引设置要选择的无线电?

1 个答案:

答案 0 :(得分:1)

您无法选择多个广播,因此def shift_int(image, base, y, x): """ Quickly shift an image with respect to a base and return a parameter that is minimized when the images are well aligned, and not biased towards large shifts image -- The input image that is shifted base -- The second image to match y -- An offset along axis 0 x -- An offset along axis 1 """ new_image = image.copy() new_base = base.copy() if y > 0: new_image = new_image[:-y] new_base = new_base[y:] if y < 0: new_image = new_image[-y:] new_base = new_base[:y] if x > 0: new_image = new_image[:,:-x] new_base = new_base[:,x:] if x < 0: new_image = new_image[:,-x:] new_base = new_base[:,:x] return np.mean((new_im-new_base)**2) 绑定不一定是广播的checked。设置输入值的最佳方法是observableArray绑定,在代码段中有两个示例,但请参阅文档Checked binding KO它非常有用。

checkedValue
function ViewModel(){
  this.container = ko.observableArray([{name: 'hello', amount: [{item: name, key: 4, selected: 0}, {item: 'name', key: 2, selected: '1'}]}, {name: 'hello', amount: [{item: name, key: 10, selected: 0}, {item: name, key: 8, selected: '1'}]}]);
   
   this.amountSelectedRadio = ko.observable(2);
   this.amountSelectedChecked = ko.observableArray([8,4]);  
  
}


ko.applyBindings(new ViewModel())

相关问题