如何将以下对象与以下模型绑定?

时间:2013-10-03 08:08:59

标签: html angularjs select

这是我的对象

$scope.status = [{ "code": "CNA", "name": "Consignee Not Available" }, { "code": "TBD", "name": "To Be Delivered" }, { "code": "CRA", "name": "Consignee Refused To Accept" }, { "code": "D", "name": "Delivered" } ]

我的HTML如下

<select ng-options="status.name for status in status" ng-model="awb.delivery_fail_reason"> <option value="">Please Select Status</option> </select>

所以我想要的是

  1. 当用户选择状态To be Delivered时 我的模型变量 awb.delivery_fail_reason应设置为TBD
  2. 当模型awb.delivery_fail_reasonTBD时,它应自动将select设置为To Be Delivered 这可能吗 ?

2 个答案:

答案 0 :(得分:1)

尝试

status.code as status.name for status in status

答案 1 :(得分:0)

在html中进行更改,如下所示

  <select ng-model="awb.delivery_fail_reason">
              <option value="">Please Select Status</option> 
              <option ng-repeat="s in status" value="{{s.code}}">{{s.name}}</option>

              </select>
试试小提琴 http://jsfiddle.net/U3pVM/1489/