gpt4 book ai didi

jquery - 无法通过发布响应更新 Bootstrap 的预输入数据源

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

使用 Bootstrap 的 typeahead javascript 插件,我尝试通过 jQuery 的 $.post 方法更改数据源属性。最初,我有:

<input type="text" data-provide="typeahead" data-source="["Option 1","Option 2","Option 3"]">

然后,假设单击一个按钮并尝试更新数据源:

 $('button').on('click',function(){
$.post('update.php',function(resp){
$('input').attr('data-source',resp);
});
});

resp XHR 结果返回一个像这样的数组:

  ["One Option","Two Option","Three Option"]

我发现这不能使用响应中构造的新数组可靠地更新数据源。

有谁知道问题出在哪里吗?

这似乎没有捕获所选值。有谁知道如何使用 Bootstrap 进行预输入来获取选定的值?

最佳答案

我最终想出了如何做到这一点。是outlined on github here

访问预输入输入的数据属性并直接修改源数组。例如:

var autocomplete = $('input').typeahead();

//where newSource is your own array
autocomplete.data('typeahead').source = newSource;

关于jquery - 无法通过发布响应更新 Bootstrap 的预输入数据源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9477095/

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