jquery オートコンプリートで select 関数がデータを台無しにする理由がわかりません。つまり、value
そうlabel
すべきではないということです。
のコンソール ログ出力console.log(val);
Object { value="1558825", label="Cree sus propias noticias cliente", icon="http://servidor...News/10_ae4e0.jpg"}
のコンソール ログ出力console.log(ui.item);
Object { label="Cree sus propias noticias cliente", value="Cree sus propias noticias cliente"}
コード:
$("#search_input").autocomplete({
source: function(req, add) {
$.getJSON("do.php", { OP: "news_search", category: cat_id, get: req }, function(results){
var suggestions = [];
$.each(results, function(i, val){
console.log(val);
suggestions.push(val.label)
});
add(suggestions);
});
},
select: function(event, ui){
console.log(ui.item); // Here value and label is the same, when it shouldn't
$("#search_input").val(ui.item.label).attr('data-target', ui.item.value);
return false;
},
minLength: 2
});
なぜそれが起こっているのですか?