AngularJS ng-options用于排除特定对象

dul*_*lan 8 angularjs ng-options

我正在使用角度ng选项来显示有几个选项作为当前类别的父类别的选择,基本上这些选项包含所有现有类别,我需要从ng-options中排除当前类别,这相当于因为某个类别不能是其自身的父类别.那我该怎么做?目前我有以下代码:

<tr ng-repeat="category in allCategories">
    <th ng-bind="category.name"></th>
    <th>
        <select ng-options="everyCategory.name for everyCategory in allCategories">
            <option value="">Select parent category</option>
        </select>
    </th>
</tr>
Run Code Online (Sandbox Code Playgroud)

小智 28

你应该使用过滤器.

<select ng-options="everyCategory.name for everyCategory in allCategories | filter: { name: '!' + category.name }">...</select>
Run Code Online (Sandbox Code Playgroud)