Kendo ui 在重新键入搜索字符串时,Kendo AutoComplete不会重新查询数据源
我有一个剑道自动完成小部件的问题 我尝试在用户输入搜索的前两个字符后查询数据源。 在服务器(web api)上,我使用这两个字符限制搜索,一切正常,即返回一个子集并正确显示,如果我继续键入搜索,则会进一步过滤 但是,我随后重新键入一个新的搜索条目,该条目不再返回到数据源,因此我只能处理从第一个查询中检索到的数据 我该如何正确地处理这件事 谢谢 以下是我的测试代码:Kendo ui 在重新键入搜索字符串时,Kendo AutoComplete不会重新查询数据源,kendo-ui,Kendo Ui,我有一个剑道自动完成小部件的问题 我尝试在用户输入搜索的前两个字符后查询数据源。 在服务器(web api)上,我使用这两个字符限制搜索,一切正常,即返回一个子集并正确显示,如果我继续键入搜索,则会进一步过滤 但是,我随后重新键入一个新的搜索条目,该条目不再返回到数据源,因此我只能处理从第一个查询中检索到的数据 我该如何正确地处理这件事 谢谢 以下是我的测试代码: public class AlbumsController : ApiController { HttpRequest _r
public class AlbumsController : ApiController
{
HttpRequest _request = HttpContext.Current.Request;
// GET api/albums
public IEnumerable<Album> GetForAutoComplete()
{
string sw = _request["sw"] == null ? "" : _request["sw"].ToString();
var query = (from a in Albums.MyAlbums
where a.Title.ToLower().StartsWith(sw)
orderby a.Title
select a).ToArray();
return query;
}
设置为true。默认值为false,因此它只抓取一次数据,并假设它现在拥有所有数据,随后的过滤在客户端上完成。
要使其每次都重新发送到服务器,请添加以下内容:
var dataSource = new kendo.data.DataSource({
serverFiltering: true, // <-- add this line.
transport: {
...
}
});
var dataSource=new kendo.data.dataSource({
serverFiltering:true,//使用kendo autocomplete从数据库键入时选择欧洲国家的代码,如下所示:
$("#countries").kendoAutoComplete({
dataTextField: "yourfield",
filter: "startswith", // or you can use filter: "contains",
minLength: 3, //what ever you want. In my case its 0.
placeholder: "Select country...",
dataSource: {
type: "get",
serverFiltering: true, //or can also make it false
transport: {
read: {
url: "/yourController/yourAction",
datatype: "json"
}
}
}
});
这对我来说很好。谢谢你-我真是个白痴,我有那条线路,但在运输部分…如果js是强类型的话…:(只是阅读你写的其他一些文章——干得不错!别难过,每次我创建一个新的数据源时,我还是要参考一下,以确保它在正确的位置:)在做了十年Java和C之后,没有intellisense,JS是很难的!可能会复制
$("#countries").kendoAutoComplete({
dataTextField: "yourfield",
filter: "startswith", // or you can use filter: "contains",
minLength: 3, //what ever you want. In my case its 0.
placeholder: "Select country...",
dataSource: {
type: "get",
serverFiltering: true, //or can also make it false
transport: {
read: {
url: "/yourController/yourAction",
datatype: "json"
}
}
}
});