Hi experts,
I'm using Kendo MultiSelect controller, I use MVVM design to bind this controller to a viewModel.
1.
<select id="selectedCategories" style="width: 700px" data-role="multiselect" data-value-field="name" data-text-field="name" data-bind="source: selectedCategoryOptions, value: selectedCategory, events: { change: selectedCategoryChange }" />
2.
var viewModel = kendo.observable({
selectedCategory: [],
selectedCategoryOptions: [],
});
3.
var preCustomSubCategories = ["newItem1"];
var selectedCategory = viewModel.selectedCategory;
var selectedCategoryOptions = viewModel.selectedCategoryOptions;
for (var i = 0; i < preCustomSubCategories.length; i++) {
var item = { name: preCustomSubCategories[i] };
if (!IsInCategoryArray(item, selectedCategory)) {
selectedCategory.push(item);
}
if (!IsInCategoryArray(item, selectedCategoryOptions)) {
selectedCategoryOptions.push(item);
}
}
viewModel.set("selectedCategoryOptions", selectedCategoryOptions);
viewModel.set("selectedCategory", selectedCategory);
If preCustomSubCategories item is exist in the options, it will be selected; but if preCustomSubCategories item is not exist in the options, it will be added to both options list and select list, but in the controller UI show nothing select. It's interesting that when i select a newItem2 again, the previous added newItem1 will show in controller UI, but newItem3 not show in controller UI.
I'm using Kendo MultiSelect controller, I use MVVM design to bind this controller to a viewModel.
1.
<select id="selectedCategories" style="width: 700px" data-role="multiselect" data-value-field="name" data-text-field="name" data-bind="source: selectedCategoryOptions, value: selectedCategory, events: { change: selectedCategoryChange }" />
2.
var viewModel = kendo.observable({
selectedCategory: [],
selectedCategoryOptions: [],
});
3.
var preCustomSubCategories = ["newItem1"];
var selectedCategory = viewModel.selectedCategory;
var selectedCategoryOptions = viewModel.selectedCategoryOptions;
for (var i = 0; i < preCustomSubCategories.length; i++) {
var item = { name: preCustomSubCategories[i] };
if (!IsInCategoryArray(item, selectedCategory)) {
selectedCategory.push(item);
}
if (!IsInCategoryArray(item, selectedCategoryOptions)) {
selectedCategoryOptions.push(item);
}
}
viewModel.set("selectedCategoryOptions", selectedCategoryOptions);
viewModel.set("selectedCategory", selectedCategory);
If preCustomSubCategories item is exist in the options, it will be selected; but if preCustomSubCategories item is not exist in the options, it will be added to both options list and select list, but in the controller UI show nothing select. It's interesting that when i select a newItem2 again, the previous added newItem1 will show in controller UI, but newItem3 not show in controller UI.