我对角度很新。 我想在我的ng-options中有一个where子句,如下所示:
select * from currencies where currency.code in ( 'usd' , 'cad')
<select ng-model="selectedCurrency" ng-options="currency.Name for currency in Currencies | filter:currency.code = 'usd' track by currency.ID">
<option value="">-- select a currency--</option>
</select>
我只能为一个代码执行此操作,但我想从两个或更多的数组中选择它!
答案 0 :(得分:2)
尝试:
ng-options="currency.Name for currency in Currencies track by currency.ID | filter: {code: 'usd'}"
要搜索多个值,您可以使用函数:
$scope.filterCurrencyCodes = function(currency) {
return (['usd', 'cad'].indexOf(currency.code) !== -1);
};
ng-options="currency.Name for currency in Currencies track by currency.ID | filter: filterCurrencyCodes"
答案 1 :(得分:0)
尝试:
ng-options="currency.Name for currency in Currencies track by currency.ID | filter: filterCurrency"
然后创建一种评估货币代码的方法:
$scope.filterCurrency= function(currency){
if(currency.code == 'USD' || currency.code == 'CAD'){
return true;
}
return false;
};