Jquery Ui Auto suggestions with Json array
Jquery Ui Auto suggestions with Json array
我正在使用jquery UI自动完成功能在列表中给出项目名称建议。我从 php 文件中以 json 数组的形式提供一个项目名称列表,如下所示。
function getProjectList($projectList) {
foreach ($projectList as $project) {
$jsonArray[] = array('name' => $project['projectName'], 'id' => $project['projectId']);
}
$jsonString = json_encode($jsonArray);
return $jsonString;
}
我正在将整个项目名称列表获取到一个 javascript 变量中。
var projectsForAutoComplete=<?php echo $timesheetForm->getProjectListAsJson(); ?>;
这个项目列表有超过10000个项目,我有20个项目名称文本框,应该提供自动建议。因此,当我尝试在加载时执行以下操作时,由于 js 的处理速度更高,页面有 30 秒的时间来加载。
$(".project").autocomplete(projectsForAutoComplete, {
formatItem: function(item) {
var temp = $("<div/>").html(item.name).text();
return temp.replace("##", "");
}
,
matchContains:true
})
所以我需要在按键事件中加载自动建议,就像 Jquery 文档中的演示一样。 http://jqueryui.com/demos/autocomplete/#remote-jsonp
但该示例显示了如何使用远程 json 源执行此操作。我可以对本地 json 数组做同样的事情吗?可能吗。有人可以帮助我吗?
如果你已经在页面上有 json 数组,那么你可以简单地将其作为源包含
source: projectsForAutoComplete
但是,自动完成功能希望它的源是 1D 数组,而您的数组是 2D。你要么需要创建两个数组,提供带有字符串作为源的数组,然后编写一个函数将名称映射到 id,要么执行类似于 jQueryUI 自动完成文档中的组合框示例的操作。
相关文章:
- 如何为json对象中的段发送array[]
- Multidim json array javascript,如何抓取值
- jquery-autocomplete with json array
- Jquery Ui Auto suggestions with Json array
- Angularjs if else condition using json array
- JSON Array for jQuery UI Autocomplete
- AngularJS ng-repeat for dynamic child json array
- foreach for javascript, json array
- AngularJS Json Array
- 如何将json/array从中的ajax responseText转换为javascript数组
- 如何从ajax responseText中获取json/array到javascript数组
- Python and a JSON Array
- 映射Json Array的值
- print[ [object Object],[object Object]] to json array
- jquery and json array
- 如果JSON Array为NULL,则返回-1,仅在某些数据中有效
- 对具有相同键的JSON Array的数量求和
- JS-构造函数(自定义库)中的JSON/ARRAY传递变量
- 访问并更改2d Json Array,Javascript
- 使用不同的json-array多次调用javascript函数