如何从选择框中显示对象的ID

时间:2014-10-20 18:51:12

标签: angularjs

我有一个包含员工列表的选择框。当我选择一个时,它将字符串值发送到控制器。我需要传递所选名称的Id,而不是名称值本身。 plunker

 <label>CustomerPM:</label>
 <select style="width: 150px" ng-options="customer.CustomerEmployeeFirstName + ' ' + customer.CustomerEmployeeLastName as customer.CustomerEmployeeFirstName + ' ' + customer.CustomerEmployeeLastName for customer in customerEmployeeArray | filter:{CustomerEmployeeRole : 'PM', CustomerId : currentItem.CustomerId}" ng-model="currentItem.CustomerEmployeePMId"> 
   <option value="" selected="selected">Select</option>
      &nbsp;
   </select><br />
     {{currentItem.CustomerEmployeePMId}}<br />
      <label>CustomerSuper:</label>
   <select style="width: 150px" ng-options="customer.CustomerEmployeeFirstName + ' ' + customer.CustomerEmployeeLastName as customer.CustomerEmployeeFirstName + ' ' + customer.CustomerEmployeeLastName for customer in customerEmployeeArray | filter:{CustomerEmployeeRole : 'Super', CustomerId : currentItem.CustomerId} " ng-model="currentItem.CustomerEmployeeSuperId">
     <option value="" selected="selected">Select</option>
       &nbsp;
    </select><br />
    {{currentItem.CustomerEmployeeSuperId}}<br/>

1 个答案:

答案 0 :(得分:1)

删除ng-options属性的第一部分customer.CustomerEmployeeFirstName + ' ' + customer.CustomerEmployeeLastName as - 并将其替换为customer.CustomerEmployeeId as

来自the docs

  

select:此表达式的结果将绑定到父元素的模型。如果未指定,则select expression将默认为value。