如何使用<select>进行第二次</select>过滤IEnumerable

时间:2017-06-23 09:30:10

标签: javascript html angularjs dictionary ienumerable

在我的角度脚本中,我通过从我的ASP.net控制器提供的viewmodel中提取以下内容来声明以下内容:

$scope.controlleractions = @Html.Raw(Json.JsonCamelCase(Model.ControllerActions));

产生以下数据:

[{"$id":"1",
"controller":"Resource",
"actions":["Image","File"]},

{"$id":"2",
"controller":"Home",
"actions":["Index","NotAuthorized"]},

{"$id":"3",
"controller":"Email",
"actions":["Index","Details","Adress"]},

{"$id":"4",
"controller":"Account",
"actions":["Index","Login","Logout","Create"]},

{"$id":"5",
"controller":"Archive",
"actions":["Page1","Page2","Page3","Search"]}]

我希望能够通过select元素选择一个控制器,然后使用第二个select元素从actions数组中选择一个动作,但我似乎无法解决它。有人有想法吗?

ng-model中的两个输出都优选为字符串

这是我有多远:

<!-- selecting a controller works fine -->
<select ng-model="selectedController">
    <option value="">All</option>
    <option ng-repeat="controlleraction in controlleractions">{{controlleraction.controller}}</option>
</select>

<!-- selecting an action from actions that match the selected controller dosn't work -->
<select ng-model="selectedAction">
    <option value="">All</option>
    <option ng-repeat="action in controlleractions.actions | filter : selectedController">{{action}}</option>
 </select>

1 个答案:

答案 0 :(得分:0)

不确定为什么在这里使用filter,而只是将ng-repeat绑定在selectedController上:

 <option ng-repeat="action in selectedController.actions">{{action}}</option>