Jquery mobile Jquery移动自动完成远程数据源
我正在编写一个具有jqm客户端和web api的应用程序。我需要有一个am输入,它使用web api所在的远程数据源自动完成 运行应用程序时,我似乎看不到web api中可用选项的下拉列表,但在调试时,我可以看到对我的服务的影响 下面是示例代码。 JQM Web API服务Jquery mobile Jquery移动自动完成远程数据源,jquery-mobile,Jquery Mobile,我正在编写一个具有jqm客户端和web api的应用程序。我需要有一个am输入,它使用web api所在的远程数据源自动完成 运行应用程序时,我似乎看不到web api中可用选项的下拉列表,但在调试时,我可以看到对我的服务的影响 下面是示例代码。 JQM Web API服务 public class ManufacturerController : ApiController { List<Manufacturer> manufacturers=new List<
public class ManufacturerController : ApiController
{
List<Manufacturer> manufacturers=new List<Manufacturer>()
{
new Manufacturer(){Id = 1, Name = "Audi"},
new Manufacturer(){Id = 2, Name = "BMW"},
new Manufacturer(){Id = 3, Name = "Mazda"},
new Manufacturer(){Id = 4, Name = "Nissan"},
new Manufacturer(){Id = 5, Name = "Ford"},
new Manufacturer(){Id = 6, Name = "Mitsubishi"},
new Manufacturer(){Id = 7, Name = "Toyota"},
new Manufacturer(){Id = 8, Name = "VolksWagen"},
new Manufacturer(){Id = 9, Name = "Renault"},
};
public IEnumerable<Manufacturer> GetManufacturers()
{
return manufacturers;
}
}
任何帮助都将不胜感激
您好,所有人都设法使用jqm.autoComplete-1.5.2-min,它似乎正在工作,我只有一个问题,我似乎看不到Web Api列表中的实际值。客户端列表中只填充了未定义的值。请参阅下面的代码
客户端
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Hyper Finance</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>
$(document).bind('mobileinit', function () {
$.mobile.selectmenu.prototype.options.nativeMenu = false;
$.mobile.selectmenu.prototype.options.hidePlaceholderMenuItems = false;
});
</script>
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"> </script>
<script src="Scripts/jqm.autoComplete-1.5.2-min.js"></script>
</head>
<body>
<div data-role="page" id="mainpage">
<div data-role="fieldcontain">
<label for="search">Your city: </label>
<input type="text" id="search" placeholder="Test">
<ul id="suggestions" data-role="listview" data-inset="true"></ul>
</div>
</div>
<script>
$("#mainpage").bind("pageshow", function (e) {
$("#search").autocomplete({
method: 'GET',
target: $("#suggestions"),
source: "http://myhost:38605/api/manufacturer",
callback: function (e) {
var $a = $(e.currentTarget);
$("#search").val($a.data('autocomplete').value);
$("#search").autocomplete('clear');
},
link: 'target.html?term=',
minLength: 1
});
});
</script>
</body>
</html>
web Api保持不变。任何帮助都将不胜感激请尝试在页面脚本之前加载jQM脚本。此外,在.thenfunctionresponse中添加alertresponse;查看您是否从web api获得了预期的结果。@ezanker。谢谢你的回复,但它不起作用。这就是我希望存档a在我键入搜索输入时看到的下拉列表b能够选择一个将显示在输入框中的选项HI all i managed use jqm.autoComplete-1.5.2-min,当我在搜索框中键入时,它似乎显示了下拉列表。我现在面临的问题是,没有看到web api中的实际值,而是用未定义的值填充整个列表,请参见下面的代码
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Hyper Finance</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>
$(document).bind('mobileinit', function () {
$.mobile.selectmenu.prototype.options.nativeMenu = false;
$.mobile.selectmenu.prototype.options.hidePlaceholderMenuItems = false;
});
</script>
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"> </script>
<script src="Scripts/jqm.autoComplete-1.5.2-min.js"></script>
</head>
<body>
<div data-role="page" id="mainpage">
<div data-role="fieldcontain">
<label for="search">Your city: </label>
<input type="text" id="search" placeholder="Test">
<ul id="suggestions" data-role="listview" data-inset="true"></ul>
</div>
</div>
<script>
$("#mainpage").bind("pageshow", function (e) {
$("#search").autocomplete({
method: 'GET',
target: $("#suggestions"),
source: "http://myhost:38605/api/manufacturer",
callback: function (e) {
var $a = $(e.currentTarget);
$("#search").val($a.data('autocomplete').value);
$("#search").autocomplete('clear');
},
link: 'target.html?term=',
minLength: 1
});
});
</script>
</body>
</html>