2016-10-03 132 views
0

我正在開發prestashop模塊,我創建了一些自定義字段吃了產品頁面。 我有從JSONPrestashop自動完成輸入類型

這裏通過自動完成得值的字段是模塊TPL場:

 <div class="form-group"> 

     <label class="control-label col-lg-3">Post 6:</label> 

     <div class="col-lg-9"> 

      {*<input type="text" name="principi_name" value="{$principi_name}">*} 

      {include 

       file="controllers/products/textarea_lang.tpl" 

       languages=$languages 

       input_name='principi_name' 

       class="textarea testingautocolplete" 

       input_value=$principi_name} 

     </div> 

    </div> 

這裏是jQuery的:

$(document).ready(function() { 

    product_tabs['product_type'] = new function(){ 
     $('.testingautocolplete').autocomplete('http://www.domain.com/dbsearch.php', { 
      width: 320, 
      max: 4, 
      highlight: false, 
      multiple: true, 
      multipleSeparator: " ", 
      scroll: true, 
      scrollHeight: 300, 
     }) 

    } 

}); 

場上的結果是所有json: 我想我犯了一個錯誤,但我找不到什麼:

enter image description here

謝謝。

回答

0

我們不知道你正在使用自動填充字段的方式,但我們已經使用了好幾次通過以下步驟:

下面的代碼添加到您的JS代碼的網頁上(在的document.ready javascript函數)

$('YOUR_FIELD_ID').autocomplete(path_fold+"/FILE_PATH_TO_HANDLE_AJAX.php",{ 
    delay: 100, 
    minChars: 1, 
    autoFill: true, 
    max: 20, 
    matchContains: true, 
    mustMatch: true, 
    scroll: false, 
    cacheLength: 0, 
    multipleSeparator: '||', 
    formatItem: function(item) { 
     return item[0]; 
    }, 
    extraParams: { 
     customerFilter: 1, 
    } 
}).result(function(event, item) { 
//Code to use the result 
}); 

PHP文件將被處理Ajax請求將簡單地準備並在所需的格式發送數據。

+0

你好,感謝您的回覆。我用你的代碼,這是好的,我吃的情況下我ajax.php只返回一個JSON這樣的:'[ 「LA-BuONa外,cosmesi枝-FA-好處 - allambiente-valori-E-valore二unimpresa -buona-dicono二叔NOI」, 「COLORE-自然漆每VISO-E-CORPO-violetto-realizzato-CON-alcanna」 ]'但它沒有顯示如在選擇形式dwropdown在情況下,我返回其結果作爲陣列JSON編碼'回波json_encode($ simplearray)'IMG:HTTP://prntscr.com/cqary9 –