【问题标题】:How to filter IEnumerable with <select> for second <select>如何使用 <select> 过滤 IEnumerable 以获得第二个 <select>
【发布时间】:2017-11-26 19:50:36
【问题描述】:

在我的 Angular 脚本中,我通过从我的 ASP.net 控制器提供的视图模型中提取来声明以下内容:

$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"]}]

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

ng-models 中的两个输出都最好是字符串

这是我走了多远:

<!-- 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>

【问题讨论】:

    标签: javascript html angularjs dictionary ienumerable


    【解决方案1】:

    不知道你为什么在这里使用filter,而只是将你的ng-repeat 绑定到selectedController 上:

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

    【讨论】:

    • 我已经尝试过了,但它不起作用。 selectedController 是一个字符串,而不是一个包含操作列表的对象。
    • 我本可以将第一个
    • 那么我认为你应该使用与实际控制器对应的第三个变量才能有它的动作。
    猜你喜欢
    • 1970-01-01
    • 2010-11-30
    • 2022-12-17
    • 1970-01-01
    • 1970-01-01
    • 2020-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多