在下拉列表中创建动态子菜单

时间:2018-01-12 08:55:23

标签: javascript angularjs

我有理由重新安排工作,也有理由的原因。我希望在选择原因时,应该出现其次要原因。我该怎么做?

<select>
  <option value="" disabled="disable" selected="selected">
      Select Reason 
  </option>
  <option ng-repeat="reasons in Resonse_schedule ">
     {{reasons.reasons}} 
  </option>
</select>

2 个答案:

答案 0 :(得分:0)

使用ng-options

AngularJS提供了一个指令ng-options来动态列出选项

  <select ng-options="reason.reason as reason.reason for reason in Resonse_schedule">
         <option value="" selected disabled >Select Reason</option>

   </select>

我建议你仔细阅读ngOptions的文档,以便更好地理解

答案 1 :(得分:0)

您可以使用:

  <select ng-model="reasonVar" ng-options="reason as reason.name for reason in Resonse_schedule">
  <option value="" disabled="disable" selected="selected">Select Reason 
  </option>
  </select>

  <select ng-model="reasonSelected">
   <option ng-repeat="subReason in reasonVar.subReasons" value="subReason.name">
     {{subReason.name}}
   </option>
  </select>

其中reasonVarResonse_schedule列表中的选定值。

以下是此代码的工作示例:
http://jsfiddle.net/U3pVM/35122/

这是一个比较复杂的问题:
http://jsfiddle.net/miparnisari/u50hgn5a/