简体   繁体   English

bootstrap-选择不选择正确的项目

[英]bootstrap-select not selecting the correct item

I am using bootstrap select Bootstrap-select v1.7.2 in Angular. 我在Angular中使用bootstrap select Bootstrap-select v1.7.2。 When I select some option from drop down it selects some other option. 当我从下拉列表中选择一些选项时,它会选择其他一些选项。

Plunker is setup here: Plunker在这里设置:

http://plnkr.co/edit/MRYOkW?p=preview http://plnkr.co/edit/MRYOkW?p=preview

(code is in dashboard.html and dashboard.js) (代码在dashboard.html和dashboard.js中)

That's how I am creating it. 这就是我创造它的方式。 bootstrap-dropdown is the directive that initiates the drop-down. bootstrap-dropdown是启动下拉列表的指令。

<select ng-model="vm.CurrCustomer.Logic" name="ddlLogic"   bootstrap-dropdown >
    <option>Contains</option>
    <option>Greater Than</option>
    <option>Less Than</option>
    <option>Equal To</option>
</select>

You missed to add value attribute on your options that would set value of ng-model on select of any option 您错过了在您的选项上添加值属性,该属性将在选择任何选项时设置ng-model

<select ng-model="vm.CurrCustomer.Logic" name="ddlLogic" bootstrap-dropdown>
    <option value="">Contains</option>
    <option value="Greater">Greater Than</option>
    <option value="Less">Less Than</option>
    <option value="Equal">Equal To</option>
</select>

Update 更新

If you want to render select option dynamically I'd refer you to use ng-options which support select perfectly. 如果你想动态渲染选择选项,我会建议你使用支持完美选择的ng-options You can select object on selection of option 您可以在选择选项时选择对象

Demo here 在这里演示

problem is you can't add option value property . 问题是你无法添加选项值属性。 either set value property or generate this using ng-repeat option 设置值属性或使用ng-repeat选项生成此属性

Above answer must be the right answer but, It seems like you had an unwanted empty option an it was messing the index. 上面的答案必须是正确的答案,但是,似乎你有一个不需要的空选项,它正在弄乱索引。 By adding a real one it started to work. 通过添加一个真正的它开始工作。

<select ng-model="vm.CurrCustomer.Logic" name="ddlLogic"   bootstrap-dropdown >
        <option></option>
        <option>Contains</option>
        <option>Greater Than</option>
        <option>Less Than</option>
        <option>Equal To</option>
</select>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM