2番目の問題に関しては、コンボボックスをオーバーライドして、不要onListSelectionChange
な値をフィルタリングするのが最善の方法です。
onListSelectionChange: function(list, selectedRecords) {
//Add the following line
selectedRecords = Ext.Array.filter(selectedRecords, function(rec){
return rec.data.parent!=0;
});
//Original code unchanged from here
var me = this,
isMulti = me.multiSelect,
hasRecords = selectedRecords.length > 0;
// Only react to selection if it is not called from setValue, and if our list is
// expanded (ignores changes to the selection model triggered elsewhere)
if (!me.ignoreSelection && me.isExpanded) {
if (!isMulti) {
Ext.defer(me.collapse, 1, me);
}
/*
* Only set the value here if we're in multi selection mode or we have
* a selection. Otherwise setValue will be called with an empty value
* which will cause the change event to fire twice.
*/
if (isMulti || hasRecords) {
me.setValue(selectedRecords, false);
}
if (hasRecords) {
me.fireEvent('select', me, selectedRecords);
}
me.inputEl.focus();
}
},
そして、コンボのnot toonBoundlistItemClick
内のアイテムのみを選択および選択解除するように変更します。boundlist
setValue
onBoundlistItemClick: function(dataview, record, item, index, e, eOpts) {
var chk = item.className.toString().indexOf('x-boundlist-selected') == -1;
if ( ! record.data.parent) {
var d = dataview.dataSource.data.items;
for (var i in d) {
var s = d[i].data;
if (s.parent == record.data.id) {
if (chk) { // select
dataview.getSelectionModel().select(d[i],true);
} else { // deselect
dataview.getSelectionModel().deselect(d[i]);
}
}
}
}
},
最初の問題に関しては、displayTpl 構成オプションを使用してラベルを簡単に追加できます。ただし、これは必要なテキストのみを追加し、スタイル (灰色など) はありません。コンボは、html タグを受け入れないテキスト入力を使用しています。ユーザーがテキストを入力する必要がない場合は、コンボの基本的な動作を変更して、テキスト入力の代わりに別の要素を使用することをお勧めします。