Checkbox 在EmberJs中为复选框选择绑定
Emberjs是否为复选框提供selectionBinding以处理选中/选中的复选框选项Checkbox 在EmberJs中为复选框选择绑定,checkbox,ember.js,Checkbox,Ember.js,Emberjs是否为复选框提供selectionBinding以处理选中/选中的复选框选项 如果是,如何操作?绑定到Ember.Checkbox的checked属性,请参阅: 把手: {{view Ember.Checkbox checkedBinding=“App.objController.isChecked”} JavaScript: App.objController=Ember.Object.create({ 我问:是的, _isCheckedChanged:函数(){ var is
如果是,如何操作?绑定到
Ember.Checkbox的checked
属性,请参阅:
把手:
{{view Ember.Checkbox checkedBinding=“App.objController.isChecked”}
JavaScript:
App.objController=Ember.Object.create({
我问:是的,
_isCheckedChanged:函数(){
var isChecked=this.get('isChecked');
log('isChecked已更改为%@'.fmt(isChecked));
}.observes('isChecked'))
});
好吧,这有点老了,但我也偶然发现了这一点。我已将复选框选项以数组形式发送到路线的模型。真正的问题在于实现双向绑定(如果这是目标的话)。我就是这样做的:
App.ItemEditController = Ember.ObjectController.extend({
isRound: function () {
return ( this.get('model.shapes').find(function(item) { return (item === 'round') }) );
}.property('model.shapes'),
isOval: function () {
return ( this.get('model.shapes').find(function(item) { return (item === 'oval') }) );
}.property('model.shapes'),
isIrregular: function () {
return ( this.get('model.shapes').find(function(item) { return (item === 'irregular') }) );
}.property('model.shapes'),
shapes: function () {
var self = this;
['round','oval','irregular'].map(function(item) {
var shapes = self.get('model.shapes');
shapes = shapes.toArray();
if (self.get('is' + item.capitalize())) {
if (shapes.indexOf(item) < 0)
shapes.push(item);
} else {
if (shapes.indexOf(item) >= 0)
shapes.splice(shapes.indexOf(item),1);
}
self.set('model.shapes', shapes);
});
}.observes('isRound', 'isOval', 'isIrregular')
});
希望这有助于任何使用这种手动双向绑定的人,您可以一次性在模型中获得所有选中的选项。好的,这只会返回一个选中的值,如果。。我们必须一次检查所有选项?
Shapes:
{{#each shape in this.shapes}}
<span class="label label-default">{{shape}}</span><br />
{{else}}
No shape selected!
{{/each}}
Shapes:
Round: {{input type="checkbox" checked=isRound}}
Oval: {{input type="checkbox" checked=isOval}}
Irregular: {{input type="checkbox" checked=isIrregular}}