如何实际提交twitter的类型数据 [英] How to actually submit data with twitter's typeahead

查看:109
本文介绍了如何实际提交twitter的类型数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Twitter的typeahead前端库进行自动完成。我的配置使用远程调用服务器。自动完成本身工作正常,但是表单标签现在拒绝在输入标签中实际输入内容(在按下回车键后)。我怀疑这是因为typeahead强制标签周围。这是我的代码:

 < form class =navbar-search form-search pull-leftaction =javascript: query_main()method =get> 
< div class =main_dropdown navbar-search>
< input class =typeaheadid =query_maintype =text>
< / div>
< / form>

下面是代码工作的时间(不带键入)


< form class =navbar-search form-search pull-leftaction =javascript :query_main()method =get>
< input type =textid =query_mainclass =main_dropdown typeahead>
< / form>

有什么想法?谢谢。

解决方案

尝试将 data-provide =typeahead输入中的属性,如官方文档示例中所示: http://getbootstrap.com/2.3 .2 / javascript.html#typeahead



如果您想对选定的项目执行更复杂的操作,可以使用例如,在你的情况下,你会把这样的东西(在jQuery中):

更新在bootstrap的typeahead选项。

  $('#query_main')。typeahead({
//一些选项
updater:function(item){
//用item
返回item;
},
//其他选项
});


I'm using Twitter's typeahead frontend library for autocompletion. My configs use remote calls to the server. The autocompletion itself works fine, however the form tag refuses to actually input the content (after pressing enter) in the input tag now. I suspect it's because typeahead forces a tag around the . Here is my code:

<form class="navbar-search form-search pull-left" action="javascript:query_main()" method="get">
    <div class="main_dropdown navbar-search">
       <input class="typeahead" id="query_main" type="text">
    </div>
</form>

Below is when the code worked (without typeahead)


<form class="navbar-search form-search pull-left" action="javascript:query_main()" method="get">
    <input type="text" id="query_main" class="main_dropdown typeahead">
</form>

Any ideas? Thanks.

解决方案

Try putting a data-provide="typeahead" attribute in the input, like in the official doc example: http://getbootstrap.com/2.3.2/javascript.html#typeahead

If you want to do something more complicated with the selected item, you could use the updater option in bootstrap's typeahead.

For instance, in your case, you would put something like this (in jQuery):

$('#query_main').typeahead({
    // Some options
    updater: function(item) {
        // Do something with item
        return item;
    },
    // Other options
});

这篇关于如何实际提交twitter的类型数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆