2016-05-02 33 views
1

我不想打印我的代碼local: ['LONDON', 'BERLIN', 'NEW YORK', 'MADRID']中的所有城市。每次用戶輸入一個字母時,我想進行查詢。x-editable typeahead ajax source

我可以使用ajax來使用自動完成和「x-editable typeahead」嗎?

HTML:

<li><label class="control-label">CITY:</label> <span id="userCity" data- 
type="typeaheadjs" data-pk="cityID" data-name="users">PARIS</span></li> 

JS:

$('#userCity').editable({ 
    url: 'ajax/editUser.php', 
    typeahead: { 
     local: ['LONDON', 'BERLIN', 'NEW YORK', 'MADRID'] 
    } 
}); 

回答

1

以防萬一這可能幫助別人,看起來像目前的1.5.1版本的X-可編輯的不支持傳遞dataset參數到typeahead構造函數。有一個拉取請求實現對此處記錄的支持https://github.com/vitalets/x-editable/pull/664

要解決此問題迅速得到,你將需要大約45行更新inputs-ext/typeaheadjs/typeaheadjs.js是:

this.$input.typeahead.apply(this.$input, this.options.typeahead); 

然後你就可以實例化X-編輯爲:

var bloodhound = new Bloodhound({ 
    remote: '/url/to/json/output' 
    // any other bloodhound options here 
}); 

bloodhound.initialize(); 

$('#editable-field').editable({ 
    type: 'typeaheadjs', 
    typeahead: [{ 
     hint: true, 
     highlight: true 
     // any other typeahead options 
    }, { 
     source: bloodhound.ttAdapter() 
     // any other dataset options 
    }] 
});