1
我只需要启用一个按钮,如果至少有一个项目被选中,另外我想绑定选定项目的计数。高级qooxdoo控制器选择绑定?
使用转换器的功能应用我来到了以下解决方案(run in qooxdoo Playground)绑定时:
// Multi-selection with <Ctrl> enabled. Click the button to clear the selection.
root = this.getRoot();
root.setLayout(new qx.ui.layout.VBox());
var model = new qx.data.Array(['one', 'two', 'three', 'four', 'five']);
var list = new qx.ui.form.List().set({selectionMode: 'multi'});
root.add(list);
var button = new qx.ui.form.Button();
button.addListener('execute', list.resetSelection, list)
root.add(button);
/**** Bindings ****/
var controller = new qx.data.controller.List(model, list);
// Enable button when there is at least one list element selected
controller.bind('selection[0]', button, 'enabled', {
converter: function (data)
{
return (data) ? true : false;
}
});
// Label button with amount of selected list items
controller.bind('selection', button, 'label', {
converter: function (data)
{
return data.length.toString();
}
});
它的工作原理,但:
有没有更好的解决方案,非常不转换的功能呢?
我搜索了“isSelected”或“selection.length”等属性,无济于事。我想了解的约束制度,并认为我失去了一些东西......
启用/通过事件失效按钮,无需绑定,甚至不太优雅,它需要的按钮最初禁用:
controller.getSelection().addListener('change', function()
{
button.setEnabled(controller.getSelection().getLength() > 0)
}, this)
button.setEnabled(false)