2015-07-09 45 views
4

有人可以幫助確定這個問題 -問題與X-編輯的引導2鍵盤緩衝

http://jsfiddle.net/xBB5x/8823/

我想實現一個X編輯(引導2)預輸入功能。

上面的jsfiddle有兩個測試。 1)本地源仿真 2)是AJAX仿真(遠程數據源)

我已經採取了從X-編輯文檔完全相同的例子,但什麼是錯的,我不能夠識別JS資源。 Typeahead沒有按預期工作。

根據我的理解,所有需要的是bootstrap 2和bootstrap.js(帶有typeahead插件的2.3.2)的bootstrap-editable.js以使其工作。

的jsfiddle代碼按照準則:

HTML

<div> 
    <p>Test 1 - local source emulation</p> 
<a href="#" id="state" data-type="typeahead" data-pk="1" data-placement="right" data-title="Start typing State.." class="editable editable-click" style="display: inline;">Arizona</a> 

</div> 
<p/> 
<div> 
    <p>Test 2 - remote data source emulation/ ajax</p> <a href="#" id="state2" data-type="typeahead" data-pk="1" data-placement="right" data-title="Start typing State.." class="editable editable-click" style="display: inline;">California</a> 

</div> 

JS

$.fn.editable.defaults.mode = 'inline'; 

//Test #1 local source emulation 
$(function() { 
    $('#state').editable({ 
     source: ["Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Dakota", "North Carolina", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"] 
    }); 
}); 

//Test #2 ajax emulation for the next step (remote data source) 
$(function() { 
    $('#state2').editable({ 
     value: 'Alabama', 
     source: function (query, process) { 
      return $.post('/typeahead', { 
       query: query 
      }, function (data) { 
       return process(data); 
      }); 
     } 
    }); 
}); 


$.mockjax({ 
    url: '/typeahead', 
    responseTime: 400, 
    response: function (settings) { 
     this.responseText = ["Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Dakota", "North Carolina", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"]; 
    } 
}); 

回答

1

我用自己的例子之前(HERE),它似乎很好地工作。 (your updated example)你正在努力實現的目標還是我錯過了什麼?

您CANH也設置在JS的所有選項,這是乾淨多了,就像這樣:

$('#state2').editable({ 
    type: 'text', 
    url: '/typeahead', 
    pk: 1, 
    title: 'Enter username', 
    ajaxOptions: { 
     dataType: 'json' 
    }, 
    success: function (response, newValue) { 
     //code here 
    } 
}); 
+0

的jsfiddle(更新例子)是行不通的。 – Rishi

+0

不工作在什麼意義上? –

+0

typeahead功能不起作用,在輸入文本框中輸入後我沒有看到任何建議。更新 - 我能夠得到這個bootstrap 3.2.0,jquery-1.9.1,typeahead.js-0.11.1。謝謝你的幫助。 – Rishi