I am very new to jquery-ui. I want to use this with ajax. (ASP.NET MVC 5) I created jquery-ui-combobox.js and added inside jquery(combobox) functions.
我对jquery-ui非常陌生。我想在ajax中使用它。(ASP。NET MVC 5)我创建了jquery-ui-combobox。在jquery(combobox)函数中添加js。
I want to use like this. Is this argument(source) correct ?
我想这样使用。这个论点(来源)正确吗?
<script>
$(function () {
$("#combobox").combobox({source: function (request, response) {
$.ajax({
url: "/Home/GetProjects",
dataType: "json",
data: {
term: request.term
},
type: "POST",
success: function (data) {
/*I dont know what I should here*/
})
);
}
});});
$("#toggle").click(function () {
$("#combobox").toggle();
});
});
</script>
Controller :
控制器:
public JsonResult GetProjects(string term)
{
var list = new List<SelectListItem>();
list.Add(new SelectListItem { Value = "1", Text = "ActionScript" });
list.Add(new SelectListItem { Value = "2", Text = "AppleScript" });
list.Add(new SelectListItem { Value = "3", Text = "Asp" });
var res = list.Where(p => p.Text.Contains(term));
return Json(res , JsonRequestBehavior.AllowGet);
}
Please help.
1 个解决方案
#1
1
In Success You can do like this...
成功时你可以这样做……
$("#combobox").append("<option value=''>Select</option>");
$.each(data, function (value, key) {
$("#combobox").append("<option value='"+key.Value+"'>"+key.Text +"</option>");
});
#1
1
In Success You can do like this...
成功时你可以这样做……
$("#combobox").append("<option value=''>Select</option>");
$.each(data, function (value, key) {
$("#combobox").append("<option value='"+key.Value+"'>"+key.Text +"</option>");
});