gpt4 book ai didi

x-editable - x-editable bootstrap 2 typeahead 的问题

转载 作者:行者123 更新时间:2023-12-01 05:03:07 29 4
gpt4 key购买 nike

有人可以帮助确定这个问题 -

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

我正在尝试实现 x-editable (bootstrap 2) typeahead 功能。

上面的 jsfiddle 有两个测试。
1) 是本地源仿真
2)是ajax仿真(远程数据源)

我从 x-editable 文档中获取了完全相同的示例,但是我无法识别的 js 资源中存在一些错误。 Typeahead 未按预期工作。

根据我的理解,它需要的只是 bootstrap-editable.js 用于 bootstrap 2 和 bootstrap.js(2.3.2 具有 typeahead 插件)才能使其正常工作。

根据指南编写 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"];
}
});

最佳答案

我以前用过他们的例子( HERE ),它似乎工作正常。是 (your updated example)你正在努力实现什么,或者我错过了什么?

您还可以在 JS 中设置所有选项,这样更简洁,如下所示:

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

关于x-editable - x-editable bootstrap 2 typeahead 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31328949/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com