Angular 1.x: data-ng-repeat 中对象的属性设置为字符串,而不是对象

Angular 1.x: attribute of an object inside data-ng-repeat is set as a string, not an object

我正在尝试将 option 字段的值设置为另一个 JSON 对象内的 JSON 对象,例如。 catalogue 里面 attribute.catalogue。问题是它被保存为 String,看起来像 JSON 对象。

我认为这在某种程度上与选项 value 字段的限制有关。我能否以某种方式调整我的代码,以便将值存储为 JSON 对象而不是字符串?

这是代码:

<div class="col-sm-3">
    <select ng-model="attribute.catalogue" ng-change="showScope()">
        <option data-ng-repeat="catalogue in catalogueObjects"
                value="{{catalogue}}">{{catalogue.name}}</option>
    </select>
</div>

一般html attribute的只能存储string的值。在 angular 世界中 ng-options 指令确实提供了在 select 选项 selected 时使用分配对象的能力。

<select ng-model="attribute.catalogue" ng-change="showScope()"
   data-ng-options="catalogue as catalogue.name for catalogue in catalogueObjects">
</select>

参考