我正在尝试制作一个预先输入的代码。但有一个类似的问题:
$.ajax({
type: "POST",
url: "system/json.php",
success: function(cevap){
var jsonString = '['+cevap+']';
var jsonObj = $.parseJSON(jsonString);
var sourceArr = [];
for (var i = 0; i < jsonObj.length; i++) {
sourceArr.push(jsonObj[i].label);
}
$(".my-auto-complete").typeahead({
source: sourceArr
});
}
});
我该如何解决?我无法理解如何配置有关typeahead
的基于javascript的配置编辑:json.php是这样的:
{"51eb585b8b3b5b531c0012be":{"_id":{"$id":"51eb585b8b3b5b531c0012be"},"takim":"Mechelen"},"51eb585b8b3b5b531c0012c5":{"_id":{"$id":"51eb585b8b3b5b531c0012c5"}
答案 0 :(得分:0)
尝试这样的事情:
$.ajax({
type: "POST",
url: "system/json.php",
success: function(cevap){
var jsonString = '['+cevap+']';
var jsonObj = $.parseJSON(jsonString);
var sourceArr = [];
for (var i = 0; i < jsonObj.length; i++) {
sourceArr.push(jsonObj[i].label);
}
typeahead = $('.my-auto-complete').data('typeahead');
typeahead.source = sourceArr;
}
});
$(".my-auto-complete").typeahead();