【发布时间】:2020-01-17 04:33:11
【问题描述】:
我是第一次尝试 Kendo 自动完成功能,但在配置时遇到了一些问题。
如果我输入 3 个字符并假设我删除文本,它会正常工作 完全来自多选字段,自动完成功能不起作用 直到我刷新页面。
当我们再次输入超过 3 个字符过滤调用 MVC 控制器时,我想避免这种情况,所以不会有很多服务器调用。(换句话说,服务器调用应该只在用户输入 3 个字符和休息时发生过滤应该发生在客户端)
这里是代码
$scope.selectOptions = {
placeholder: "Search...",
noDataTemplate: 'No data found',
dataTextField: "Name",
dataValueField: "Id",
valuePrimitive: false,
autoBind: false,
//filter: "contains",
animation: {
close: {
effects: "fadeOut zoom:out",
duration: 300
},
open: {
effects: "fadeIn zoom:in",
duration: 300
}
},
minLength: 3,
dataSource: {
//type: "odata",
serverFiltering: true,
serverPaging: true,
pageSize: 10,
filtering: function (e) {
var filter = e.filter;
if (!filter.value) {
//prevent filtering if the filter does not value
e.preventDefault();
}
},
transport: {
read: {
url: "/Configuration/GetData",
type: 'GET',
dataType: 'json'
},
parameterMap: function (options, type) {
if (type === "read") {
var paramMap = kendo.data.transports.odata.parameterMap(options);
delete paramMap.$inlinecount; // <-- remove inlinecount parameter.
delete paramMap.$format; // <-- remove format parameter.
// return paramMap;
return { searchCriteria: options.filter.filters[0].value};
}
},
schema: {
data: function (data) {
return data; // <-- The result is just the data, it doesn't need to be unpacked.
},
total: function (data) {
return data.length; // <-- The total items count is the data length, there is no .Count to unpack.
}
}
}
}
};
$scope.selectedIds = [1, 2];
<select kendo-multi-select k-options="selectOptions" k-ng-model="selectedIds" k-min-length="3" class="form-control"></select>
【问题讨论】:
标签: angularjs kendo-ui autocomplete