我有一个像这样的对象数组:
$scope.countries = [{Name: "Taiwan", Cities: ["1","2","3"]}, {Name: "Usa", Cities: ["1","2","3"]}] ;
现在我尝试使用过滤器在城市上制作ng选项:
<input ng-model="search.Name">
代码不起作用:
<select ng-model="selectedCountry" ng-options="o for o in countries.Cities | filter:search:strict"></select>
我设法让它与ng repeat和ul li一起工作,但我遇到了性能问题,因为我的真实阵列对于每个国家都有1500-2000个城市..
答案 0 :(得分:0)
如果您想在选择选项中使用单个国家/地区城市,请使用以下代码:
/**
* System configuration for Angular samples
* Adjust as necessary for your application needs.
*/
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: 'app',
// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
// other libraries
'rxjs': 'npm:rxjs',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api',
'ng2-orm': 'npm:ng2-orm'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
main: './main.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
},
'angular-in-memory-web-api': {
main: './index.js',
defaultExtension: 'js'
},
'ng2-orm': {
main: './dist/js/index.js',
defaultExtension: 'js'
}
}
});
})(this);
答案 1 :(得分:0)
试试这个
<select ng-model="selectedCountry" ng-options="o for o in search.Name.Cities"></select>