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)