如何根据预先选择过滤选择框

时间:2014-10-19 18:03:35

标签: angularjs

当我创建新作业时,我根据属性“CustomerEmployeeRole”选择客户和客户员工。我从先行输入中选择了一个客户。我需要选择过滤2个选择框,其中Customer Employees与所选客户具有相同的CustomerId。我创造了一个plunkr。 plunker

<label>Customer:</label>
<input type="text" ng-model="currentItem.CustomerName"
  typeahead="customer.CustomerName for customer in customerArray | filter:$viewValue"
  typeahead-on-select="selectCustomer($item)">

 <label>CustomerPM:</label>
 <select ng-options="customer.CustomerEmployeeFirstName + ' ' +    customer.CustomerEmployeeLastName as customer.CustomerEmployeeFirstName + ' ' +  customer.CustomerEmployeeLastName for customer in customerEmployeeArray | filter: {CustomerEmployeeRole : 'PM'}" ng-model="currentItem.CustomerEmployeeId"> 
 <option value="" selected="selected">Select</option>
 </select>

 <label>CustomerSuper:</label>
 <select ng-options="customer.CustomerEmployeeFirstName + ' ' + customer.CustomerEmployeeLastName as customer.CustomerEmployeeFirstName + ' ' + customer.CustomerEmployeeLastName for customer in customerEmployeeArray | filter:{CustomerEmployeeRole : 'Super'} " ng-model="currentItem.CustomerEmployeeId">
 <option value="" selected="selected">Select</option>
 </select>

1 个答案:

答案 0 :(得分:1)

我认为你需要做这样的事情:

<select ng-options="customer.CustomerEmployeeFirstName + ' ' + customer.CustomerEmployeeLastName as customer.CustomerEmployeeFirstName + ' ' + customer.CustomerEmployeeLastName for customer in customerEmployeeArray | filter:{CustomerEmployeeRole : 'Super', CustomerId : currentItem.CustomerId} " ng-model="currentItem.CustomerEmployeeId">

我的意思是你需要下一个过滤器:

filter:{CustomerEmployeeRole : 'Super', CustomerId : currentItem.CustomerId}

现在,您将看到Customer Employees Superid typeahead中选择的角色currentItem.CustomerIdCustomerPM

更改了plunk:http://plnkr.co/edit/r0Y2b8WvUNjyg5fKLDsL?p=preview

P.S。我认为您的CustomerSuperSelect模型错误:它们是相同的,因此当您选择PM时 - Super具有相同的值,而在选择框中它变为select。为这两个{{1}}选择不同的模型,所有模型都可以正常工作。