Reputation: 580
Background:
I getting values from a db that will be needed to be pre-selected in a kendo multi select. I am able to do this with one word, however when the return value from the DB is multiple words I run into problems.
Problem:
I am not able to populate pre-selected values in my kendo multi select. In the best cases when I only get one returned word I am able to run these two lines var value = multiSelect.value(); multiSelect.value(["test"]);
and the multi select would be populated with the test selection. However when I do multiple values from an array, it does not work the same way.
Code:
var keyWordPool = [{Words: "Test"},{Words: "Test2"}, {Words: "Test3"},
{Words: "Test4"},{Words: "Test5"}];
var returnedWords = ["Test","Test4", "Test5"]; **<< This does not work**
var returnedWords = ["Test"]; **<< This does work**
CreateandPopulateMultiSelect(keyWordPool, returnedWords)
function CreateandPopulateMultiSelect(dataSource, wordsToPopulate)
{
var multiSelect = $(".PanelMultiSelect").kendoMultiSelect({
dataSource: dataSource,
filter: "contains",
dataTextField: "Words",
dataValueField: "Words",
select: function (e) {
var item = e.item;
var text = item.text();
var stop = 0;
}
}).data("kendoMultiSelect");
var value = multiSelect.value();
multiSelect.value([wordsToPopulate]);
}
Objective:
I am not able to control the amount of words that come back from the DB, so I will need to be able to add multiple words at any given time, as well as one word. I will need to have wordsToPopulate to already be selected when a person opens a panel bar.
Upvotes: 1
Views: 4716
Reputation: 3169
Well, I can't tell you exactly what is happening internally in kendo, but your wordsToPopulate variable is already an array when you pass it in to CreateandPopulateMultiSelect(). If you change
multiSelect.value([wordsToPopulate]);
to
multiSelect.value(wordsToPopulate);
it should work.
http://dojo.telerik.com/@Stephen/aMEma
Upvotes: 4