javascript - Angular 多个 ng-options 父/子

标签 javascript angularjs ionic-framework ng-options

我有许多select输入子项,这些子项的数据根据​​父项的选择而变化。

请参阅此Codepen用于形成我的父子关系的数据类型。

我的起始代码在这里:

Controller

$scope.params = ['Sets', 'Reps', 'Colour', 'Time', 'Weight'];

$scope.children = [{
    'Sets': ['1', '2', '3', '4', '5']
  }, {
    'Reps': ['1', '2', '3', '4', '5']
  }, {
    'Colour': ['Red', 'Green', 'Blue', 'Yellow', 'Pink']
  },

];

HTML

<label class="item item-input item-select">
    <div class="input-label positive">
        Param
    </div>
    <select ng-model="param">
        <option ng-repeat="param in params" value="{{param}}">{{param}}</option>
    </select>
</label>
<label ng-show="param" class="item item-input item-select">
    <div class="input-label positive">
        Sets
    </div>
    <select ng-model="param">
        <option ng-repeat="param in params" value="{{param}}">{{param}}</option>
    </select>
</label>

仅当选择相应的父级时,子级才可见。

最佳答案

我会像这样更改模型:

$scope.params = ['Sets', 'Reps', 'Colour', 'Time', 'Weight'];

$scope.children = {
  'Sets': ['1', '2', '3', '4', '5'],
  'Reps': ['1', '2', '3', '4', '5'],
  'Colour': ['Red', 'Green', 'Blue', 'Yellow', 'Pink']
};

然后做这样的事情:

http://codepen.io/anon/pen/RPZzdM

关于javascript - Angular 多个 ng-options 父/子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30900835/

相关文章:

javascript - 在急切加载期间,错误 : Tried to select attributes using Sequelize. 强制转换或 Sequelize.fn 未指定结果别名

javascript - Google Place API - 接收数据的 jQuery JSON 解析

javascript - Parse/AngularJS - 使用用户 ID 输入数据

javascript - 在 Angular-fullstack 上用 ui-router 替换 ng-router

javascript - 在 sqlite 中出现错误,例如 ionic1 中的查询

html - 有人可以解释一下 css 中称为 dots-per-CSS-inch 而不是 dots-per-physical-inch 的错误吗

javascript - 将标记与 jsx 结合起来

javascript - Paypal 按钮使用 AngularJS 一次提交多个项目

javascript - $http.get 之后 View 未更新

javascript - 将 Ionic 标签从 ts 文件附加到 html