如何从外部.js文件中替换Kendo UI MultiSelect dataSource值...
PS :实际值来自index.html
文件,如下所示:
的index.html
<select multiple="multiple" class="city_fields initi-select-218" id="test">
</select>
var data = [
"New Jersey",
"San Francisco",
"Las Vegas",
"Chicago",
"Los Angeles",
"New York"
];
jQuery(".city_fields").kendoMultiSelect({
dataSource: data,
filter: "contains",
});
以上值我试图从init.js(外部)文件替换如下...
init.js
尝试选项1:
var newData = ["Delhi", "Bangalore"];
jQuery(".initi-select-218").kendoMultiSelect({
dataSource: newData,
filter: "contains",
placeholder: "Select",
});
尝试过选项2:
var newData = ["Delhi", "Bangalore"];
$("#test").kendoMultiSelect({
dataSource: newData,
filter: "contains",
placeholder: "Select",
});
$("#test").setDataSource(new kendo.data.DataSource({ data: newData }));
尝试过选项3:
var newData = ["Delhi", "Bangalore"];
var multiselect = $("#test").data("kendoMultiSelect");
multiselect.setDataSource(new kendo.data.DataSource({ data: newData }));
对于选项2&amp; 3,我收到错误
Uncaught TypeError: $(...).setDataSource is not a function
...
但是,它仍然是从index.html
file
答案 0 :(得分:1)
这是因为你有css类的jquery选择器。 kendo multiselect
也将相同的类应用于包装器。
<div class="k-widget k-multiselect k-header city_fields initi-select-218" unselectable="on" title="" style="">
...
<select multiple="multiple" class="city_fields initi-select-218" data-role="multiselect" aria-disabled="false" aria-readonly="false" style="display: none;">
...
</select>
</div>
改为使用id
属性:
<select id="multiselect" multiple="multiple" class="city_fields initi-select-218"></select>
<script>
$("#multiselect").kendoMultiSelect({...});
var multiselect = $("#multiselect").data("kendoMultiSelect");
...
</script>