Angularjs ng-options循环json数据问题及解决方案

1、数据

 

[{"code":"subwayLine1"},{"code":"subwayLine2"},{"code":"subwayLine3"},{"code":"subwayLine4"},{"code":"subwayLine5"},{"code":"subwayLine6"},{"code":"subwayLine7"},{"code":"subwayLine8"}]

 

 

2、ng-options循环下拉列表

 

<select class="form-control" ng-model="code" ng-options="v.code for v in codeList">
  <option value="">--请选择--</option>
</select>

 结果查询参数错误(code: $scope.code):

form表单内容:

code[code]:subwayLine1

 解决方案之一:

var params = {
  code: $scope.code
};

 

解决方案之二:

<select class="form-control" ng-model="code">
  <option value="">--请选择--</option>
  <option ng-repeat="v in codeList">{{v.code}}</option>
</select>

 

ng-options使用指南:http://each.sinaapp.com/angular/tutorial/ng-options.html

 

你可能感兴趣的:(每天进步一点点,AngularJS,纵观千象,虚线永无止境)