gpt4 book ai didi

jquery - Twitter 提前输入自动完成功能以动态添加输入

转载 作者:行者123 更新时间:2023-12-03 22:44:08 24 4
gpt4 key购买 nike

我在我的网站上使用 Twitter typeahead,效果很好。但是当我尝试动态添加新输入时,它不起作用。可能是什么问题呢?

感谢您的回复。

    var custom = new Bloodhound({
datumTokenizer: function(d) { return d.tokens; },
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: 'http://'+window.location.hostname+'/invoice/loadItemOption?query=%QUERY'
});

custom.initialize();

$('.typeahead_option_items').typeahead(null, {
name: 'item_title[]',
displayKey: 'invoice_item_option_title',
source: custom.ttAdapter(),
hint: (App.isRTL() ? false : true),
}).on('typeahead:selected', function (obj, value) {
console.log(value.invoice_item_option_title);
});

最佳答案

我所做的是将其包装到一个函数中

function typeahead_initialize() {
var custom = new Bloodhound({
datumTokenizer: function(d) { return d.tokens; },
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: 'http://'+window.location.hostname+'/invoice/loadItemOption?query=%QUERY'
});

custom.initialize();

$('.typeahead_option_items').typeahead(null, {
name: 'item_title[]',
displayKey: 'invoice_item_option_title',
source: custom.ttAdapter(),
hint: (App.isRTL() ? false : true),
}).on('typeahead:selected', function (obj, value) {
console.log(value.invoice_item_option_title);
});
}

typeahead_initialize();

与添加我运行的动态输入之前相比

$('.typeahead_option_items').typeahead('destroy');

以及创建元素之后

typeahead_initialize();

对我有用,希望这有帮助。

关于jquery - Twitter 提前输入自动完成功能以动态添加输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22321101/

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