我是一个完整的noob与
JSON解析jQuery.想到我得到了回应…我的数据是这样的:
Array( [1]=>abc,[3]=>mango,[4]=>apple,[5]=>fruits )
这样我希望这个列表显示为一个自动完成列表.我在用.
jQuery("#name").autocomplete( '<?php echo HTTP_PATH.'/songs/sss'; ?>',{ multiple: true,mustMatch: true,matchContains: true,autoFill: false,dataType: "json",parse: function(data) { return jQuery.map(data,function(item) { return { data: item,value: item.label,result: item.label}; }); },formatItem: function(item) { return item.label; },formatResult: function(item) { return item.id; },formatMatch: function(item) { return item.label; } });
我想要的值,当它显示列表,即从我的数据的标签.当我选择一个标签,它应该显示标签.但是在提交时应该提交密钥.
我的意思是我希望它作为HTML的选择框.
已返回的JSON
[{"id":1,"label":"Mehdi Hassan"},{"id":2,"label":"Jagjit Singh"},{"id":3,"label":"Suresh Vadekar"}]
解决方法
你的JSON似乎不是一个数组,只是一个对象(哈希映射).
查看官方 docs:
查看官方 docs:
Expected data format
The data from local data,a url or a callback can come in two
variants:
An Array of Strings: [ “Choice1”,“Choice2” ]
An Array of Objects with label and value properties: [ { label: “Choice1”,value: “value1” },
… ]
在你的情况下,它应该是以下格式:
[ {"1":"Shad.aab"},{"158":"Adadad"},{"159":"Asdadad"},{"166":"Abbas"},{"167":"Sdadad"},{"171":"Shadaab Please check it out"},{"173":"Check This Please"},]
(记住左侧是标签,正确的值,我想在你的数据,都应该反转…)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。