剣道コンボボックスを再バインドするときにこの問題が発生しました。基本的に、ユーザーが入力したかのようにサーバーに再クエリを実行する必要がありました。クエリが完了すると、以前に選択した値を使用して正しいアイテムを選択します。
var comboBoxElem = $("#controlNameHere");
comboBoxElem.kendoComboBox(
{
placeholder: "Start typing...",
dataTextField: "yourDataTextField", // field used in the re-query due to 'contains' filter
dataValueField: "yourDataValueField",
filter: "contains",
change: selectFunc,
dataSource: {
serverFiltering: true,
pageSize: 20,
transport: {
read: {
url: "http://yourUrlHere"
}
}
}
});
// the following code is all about re-selecting the previous value
var comboBox = comboBoxElem.data('kendoComboBox');
var previousTextValue = 'text of the previous entry here';
var previousValue = '543';
comboBox.text(previousTextValue); // to show the user text while re-query takes place
// reload previous item(s) from server, then re-select the desired item
comboBox.dataSource.query({
filter: { operator: "contains", field: 'yourDataTextField', value: previousTextValue },
complete: function () {
setTimeout(function () {
comboBox.select(function (dataItem) {
return dataItem.yourDataValueField == previousValue;
});
}, 200); //allow the observable collection to be updated (no event I know of helps here :(
}
});
うまくいけば、これは十分に明確です。私は無害なものを保護するためにコードをインラインに変更したため、わずかな構文エラーがある可能性があります。
コントロールのオプション (セットアップ) で使用するフィルターは、簡単にするために再クエリに使用するものと同じである必要があることに注意してください。そうしないと、サーバーに複数のフィルターが送られます。