简体   繁体   English

jqueryui自动完成功能如何与Json一起使用?

[英]How jqueryui autocomplete works with Json?

I have a problem with jquery ui... 我在使用jQuery UI时遇到问题...

This code sample is not working and i don't see why, have you got an idea why ? 该代码示例不起作用,我不明白为什么,您知道为什么吗?

js : js:

    $('#form_tags').autocomplete({
    source: function (requete, reponse) { // les deux arguments représentent les données nécessaires au plugin
        $.ajax({
            url: '/blog/tags.json', // on appelle le script JSON
            dataType: 'json', // on spécifie bien que le type de données est en JSON            
            success: function (donnee) {
                console.log(donnee);
                reponse($.map(donnee, function (objet) {
                    return objet.TagLib,objet.TagLib; // on retourne cette forme de suggestion
                }));
            }
        });
    }
});

json : json:

[{"tagLib":"Miel"},{"tagLib":"bon"},{"tagLib":"louis"}]

Change this: 更改此:

reponse($.map(donnee, function (objet) {
  return objet.TagLib,objet.TagLib; // on retourne cette forme de suggestion
}));

to this: 对此:

reponse($.map(donnee, function (objet) {
  return {
    label: objet.tagLib,
    value: objet.tagLib,
  };
}));

Here is working example 这是工作示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM