如何替换外部 .js 文件中的 Kendo UI MultiSelect 数据源值...
PS:实际值来自index.html
如下文件:
索引.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 (外部)文件替换如下......
初始化.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 和 3,我收到错误消息
Uncaught TypeError: $(...).setDataSource is not a function
...
但是,它仍然从index.html
文件中获取值