少なくとも1つのアイテムが選択されている場合にのみボタンを有効にする必要があります。さらに、選択したアイテムの数をバインドする必要があります。高度なqooxdooコントローラ選択のバインディング?
// 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();
}
});
それは動作しますが、しかし:私は以下のソリューション(run in qooxdoo Playground)に来たバインディング適用する際に、コンバータ機能を使用して
は、理想的には、コンバータ機能のないよりよい解決策は、ありますか?
「isSelected」や「selection.length」のようなプロパティは検索しませんでした。私はバインディングシステムを理解したいと私は
イベントを経由してボタンを無効/有効にしています...何かが欠けていると思う、束縛なし、でもあまりエレガントであり、それは最初に無効にするボタンが必要です。
controller.getSelection().addListener('change', function()
{
button.setEnabled(controller.getSelection().getLength() > 0)
}, this)
button.setEnabled(false)