Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 如何使用带值和文本的“角度ui选择”选定项_Angularjs_Angular Ui_Ui Select2_Ui Select - Fatal编程技术网

Angularjs 如何使用带值和文本的“角度ui选择”选定项

Angularjs 如何使用带值和文本的“角度ui选择”选定项,angularjs,angular-ui,ui-select2,ui-select,Angularjs,Angular Ui,Ui Select2,Ui Select,我有一份已加载到的国家列表 代码的详细信息如下所示 %ui-select{'ng-model' => 'item.country', 'append-to-body' => 'true', 'search-enable' => 'true', 'them' => 'bootstrap'} %ui-select-match{'allow-clear' => 'true', placeholder: :'select country'}

我有一份已加载到的国家列表

代码的详细信息如下所示

%ui-select{'ng-model' => 'item.country', 'append-to-body' => 'true', 'search-enable' => 'true', 'them' => 'bootstrap'}
                %ui-select-match{'allow-clear' => 'true', placeholder: :'select country'}{{$select.selected.name}}
                %ui-select-choices{'repeat' => "country.code as country in countries | filter:$select.search"}
                  %span {{country.name}}
每个对象国家都有两个属性:代码和名称 当我选择一个项目时,该值和显示的文本总是名称

我希望在选择项目时,值为“代码”,显示的文本为“名称”。 %ui选择选项元素可以变成 像这样:

%option{'ng-repeat' => "country in countries", 'value' => '{{country.code}}', 'text' => '{{country.name}}'}
如何解决此问题?

试试看
country.code as country.name for countries in countries

如果我们使用表达式country.code as country.name for countries in countries in repeat会出现错误。此表达式适用于ng选项