2016-01-08 129 views
0

我正在致力於自動完成建議基於AutoComplete plugin。我正在使用html js css.Its,當我使用var currency = [「a」,「b」,「a1」,「a2」,「a3」];但它不工作,當我使用JSON響應。當我在輸入字段上鍵入它給未捕獲TypeError:無法讀取屬性'toLowerCase'的未定義的錯誤,但它的工作使用var currency = [「a」,「 b」, 「A1」, 「A2」, 「A3」];自動搜索建議不起作用

/**js for invoking backend service which is in json format**/ 
 

 
function wlCommonInit() { 
 
    var currencies = []; 
 

 
    function empautos(result) { 
 
    WL.Logger.debug("feed retrieve successsss"); 
 
    es1(result.responseJSON.Envelope.Body.processResponse.EmpList); 
 
    } 
 

 
    function es1(result) { 
 
    WL.Logger.debug("Checking here"); 
 
    for (var i = 0; i <= result.length; i++) { 
 
     currencies[i] = result[i].ENAME; 
 
     WL.Logger.debug(currencies); 
 
     //console 
 
     /** ["1, Approver","1222430837 lastname, Mr. 1222430837 firstname", 
 
     "A Bakker","A Chunekar","A Gopalan","AGD, Mr. APPROVER","APPROVER, JOURNAL","Aachen, Torben","Aafjes , B"] **/ 
 
    } 
 
    } 
 

 
    $('#autocomplete').autocomplete({ 
 
    lookup: currencies 
 
    }); 
 

 

 
}

<div id="searchfield"> 
    <form> 
     <input type="text" name="currency" class="biginput" id="autocomplete"/> 
    </form> 
</div> 

回答

0

從我從插件的文檔,瞭解你有你的數據轉換成這種格式:[{數據: '',值: ''} ]。基本上,一組對象和每個對象應該有密鑰datavalue

所以我操縱象下面

var data = [ 
    "1, Approver", 
    "1222430837 lastname, Mr. 1222430837 firstname", 
    "A Bakker", 
    "A Chunekar", 
    "A Gopalan", 
    "AGD, Mr. APPROVER", 
    "APPROVER, JOURNAL", 
    "Aachen, Torben", 
    "Aafjes , B" 
]; 

data = data.map(function(item) { 
    return {data: item, value: item}; 
}); 
數據

Here is the working code.

+0

貨幣= currencies.map(函數(項目){ \t返回{數據:項,值:項}; – hume

+0

是這是我需要改變 – hume

+0

是的,試試看吧 – blessenm