Angular Chosen-Don't将ng模型绑定到整个对象

Angular Chosen - Don't bind ng-model to entire object

本文关键字:绑定 模型 对象 ng Chosen-Don Angular      更新时间:2023-09-26

使用角度选择

https://github.com/localytics/angular-chosen

并测试以下示例

<select multiple
        chosen
        ng-model="state"
        ng-options="s.name for s in states">
  <option value=""></option>
</select>

然而,我想知道如何将状态对象的名称值绑定到ng模型?

所提供的选项将只显示状态名称,但当选择时,整个状态对象将绑定到ng模型,而不仅仅是所选的名称。

任何想法都会一如既往地受到赞赏!

您可以尝试这种格式的

select as label for value in array

例如。s.name as s.name for s in states