jQuery的smartAutocomplete与无限滚动 [英] jquery smartAutocomplete with infinite scroll
问题描述
我们如何可以有无穷远滚动自动完成组合?
我发现无穷远滚动自动完成jQuery UI的,但是这个自动完成由pagemethods获取数据。但我想用它在MVC应用程序,并希望使用一个控制器的动作检索数据。
使用这个自动完成由pagemethods应该这样做:
how we can have autocomplete combo with infinit scroll? i found an autocomplete jquery ui with infinit scroll, but this autocomplete gets data by pagemethods. but i want to use it in mvc application and want to use an action of a controller to retrieving data. to use this autocomplete by pagemethods should do this:
$(document).ready(function () {
//Input for testing purposes
$("#inp").smartautocomplete({
getDataFunc: getData,
pageSize: 15,
autoFocus: true
});
});
//Function the SA plugin called when data is needed.
var getData = function (input, pageIndex, pageSize, callback) {
PageMethods.GetData(input, pageIndex, pageSize, function (response) {
if (response) {
response = $.map(response, function (item) {
return {
label: item,
value: item
}
});
callback(response);
}
else callback();
});
};
但我改变通过获取数据的方式$阿贾克斯:
but i change the way of getting data by using $.ajax:
var getData = function (input, pageIndex, pageSize, callback) {
$.getJSON(
{ url: '@Url.Action("GetData", "Home")' },
{ input: input, pageIndex: pageIndex, pageSize: pageSize },
function (response) {
if (response) {
response = $.map(response, function (item) {
return {
label: item,
value: item
};
});
callback(response);
}
else callback();
});
};
但它不工作,而且动作不叫。
这是自动完成访问这里:
的http://www.$c$cproject.com/Articles/325719/JQueryUI-smartAutocomplete?fid=1683905
我想知道是否有任何其他的解决方案,有无穷远滚动自动完成
i want to know if there is any other solution to have autocomplete with infinit scroll
推荐答案
替换AJAX调用PageMethod的通话
Replace PageMethod call with AJAX call
$.ajax({
url: '@Url.Action("GetData", "Default")',
type: 'GET',
dataType: 'json',
data: {
input: input,
pageIndex: pageIndex,
pageSize: pageSize
},
success: function (response) {
//alert(response);
if (response) {
response = $.map(response, function (item) {
return { label: item, value: item };
});
callback(response);
} else {
callback();
}
},
error: function (e) {
alert('error' + e);
},
contentType: 'application/json; charset=utf-8'
});
请确保您的控制器操作返回JSONResult
Make sure your controller action is returning JSONResult
return new JsonResult {JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = data };//new {result = data}
希望这有助于。
这篇关于jQuery的smartAutocomplete与无限滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!