我在将对象内部的数组放入 ng-options 时遇到问题。
我在另一个数组中有以下对象数组:
$scope.array = [{name: "jan", ar=["car", "bus", "bike"]}, {name: "tom", ar=["milk", "water", "bike", "walking"]}, {name: "kim", ar=["star", "car"]}]
我想选择 jan、tom 和 kim 选项。但这不是问题:
<select ng-options="o.name for o in array" ng-model="choosen.nOption">
但是,当他们选择一个选项时,一个新的选择应该以该名称的数组 ar 作为选项开始:
<select ng-if="choosen.nOption!=undefined" ng-options="o.ar for o in array.ar | filter: {name: choosen.nOption}">
谁能帮助我如何获取内部数组的值?
你可以在https://jsfiddle.net/brokenhip/phxyap8a/找到一个提琴手
解决方案: https ://jsfiddle.net/brokenhip/phxyap8a/2/
<select ng-options="o.name for o in arrayA" ng-model="choosen.nOption"></select>
<select ng-if="choosen.nOption!=undefined" ng-options="o for o in choosen.nOption.ar" ng-model="choosen.nOption2"> </select>