基本上,我正在尝试填充选择框,但会连接first_name
列和last_name
列中的值。
我想做什么(不起作用):
<select ng-model="buyers" ng-options="b.id as (b.first_name + " " + b.last_name) for b in buyers"></select>
工作原理:
<select ng-model="buyers" ng-options="b.id as b.first_name for b in buyers"></select>
答案 0 :(得分:130)
报价很重要。它不会使用双引号内的双引号或单引号内的单引号。
工作原理:
<select ng-model="buyers" ng-options='b.id as (b.first_name + " " + b.last_name) for b in buyers'></select>
答案 1 :(得分:4)
您可以使用此synthax连接字符串:
xmllint --relaxng user.rng --noout user.xml
user.xml validates
以下代码段连接ng-options="i.x + ' ' + i.y for i in items"
和firstname
:
lastname
angular.module('myApp', []);
function MyCtrl($scope) {
$scope.names = [{firstname: 'Jon', lastname: 'Snow'},
{firstname: 'Rob', lastname: 'Stark'},
{firstname: 'Ned', lastname: 'Stark'}];
}
请注意,括号不是必需,但它可以提高可读性。
答案 2 :(得分:0)
试试这个
<select ng-model="buyers" ng-options="b as (b.first_name + " " + b.last_name) for b in buyers">
</select>