叽叽喳喳与Knockoutjs引导自动完成下拉/组合框 [英] twitter bootstrap autocomplete dropdown / combobox with Knockoutjs

查看:293
本文介绍了叽叽喳喳与Knockoutjs引导自动完成下拉/组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我必须使用自动完成自举下拉列表中的要求,但用户可以在下拉菜单中自由格式文本,如果他们的愿望。之前你想想预输入,我可以用引导预输入文本框,但我需要有下拉becasue我们希望给在情况下,用户的一些默认值领先地位的选择不知道该怎么寻找。

I have a requirement where I HAVE TO use bootstrap autocomplete dropdown, BUT user can have free form text in that dropdown if they wish. Before you think about TypeAhead, I could use Bootstrap TypeAhead textbox, but I need to have the dropdown becasue we want to give some default values as headstart options in case users dont know what to search for.

因为这为我们创造了一个选择控制我用这与MVC DropDownListFor。

I am using this with MVC DropDownListFor as that creates a select control for us.

我发现这篇文章,其中会替我。

I found this article which does that for me.

<一个href=\"https://github.com/danielfarrell/bootstrap-combobox/pull/20\">https://github.com/danielfarrell/bootstrap-combobox/pull/20

我所要做的就是在选择控制起飞的名称和控制是让我进入自由格式文本。所有好为止。

All I had to do was take off the name from the select control and the control was letting me enter free form text. All good so far.

现在,我与Knockoutjs结合使用这一点。我结合我的选项,并选择价值选择控制,然后呈现我的模板的行,我叫(选择).combobox(),这使得选择控制引导comobobox,并增加了一个输入控制和隐藏在场景选择控制后面。

Now, I am using this in conjunction with Knockoutjs. I bind my options and selected value to the select control and then on row rendered of my template, I called (selector).combobox() which makes the select control a bootstrap comobobox and adds an input control and hides the select control in the scenes behind.

现在的问题是,当我试图让他看重张贴到服务器,因为我把在输入框中的值是不是从我给选择控制选项的有效选项,它总是将其设置为第一个选项默认。这是becasue,我设置所选值对选择的控制,而不是这是由引导-combobox.js创建输入框的结合。

The problem now is when I try to get he values to post to server, since the value I put in input box is not a valid options from the options I gave to select control, it is always setting it to the first option by default. This is becasue, I set the binding of the selected value on select control and not on the input box which was created by bootstrap-combobox.js.

我的问题是如何获取的输入框数据绑定到同一porperty的选择控制是必然。

My question is how do I get the input box to data-bind to the same porperty as the the select control was bound to.

任何其他的选择?
让我知道如果你需要更多的澄清或有疑问。
请建议。

Any other options?? Let me know if you need more clarification or have questions. Please suggest.

感谢。

推荐答案

看一看 选择二为引导 。它应该能够做你需要的一切。

Have a look at Select2 for Bootstrap. It should be able to do everything you need.

另一个很好的选择是 Selectize.js 。这感觉多一点本地来引导。

Another good option is Selectize.js. It feels a bit more native to Bootstrap.

这篇关于叽叽喳喳与Knockoutjs引导自动完成下拉/组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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