如何在 ng-options 中创建两个属性的组合 "name"
how to create a combination of two properties as "name" in ng-options
通常我们做的是
...}}_{{$index}}" ng-options="option.serial_no as option.NameRelation for option in fullFamilydetails" ng-model="obj.ch6a_decl_fam_memb_id">
然后 Java 我正在做
...
familyDetails.put("NameRelation", Emp_FamilyInfoTemp.getName()+"-"+Emp_FamilyInfoTemp.getRelation());
}else{
...
如您所见,我在 java 上处理它以将 "NAME" - "RELATION" 对显示为 "name of ng-options"
但我想要的是在 json 中将 NAME 和 RELATION 保留为不同的属性,但在创建 ng-options 时显示它们的组合,我想在保留属性的同时创建相同的效果分开。
当前样本 Json
[{"DOB":"2014-09-03 00:00:00.0","NameRelation":"MaleChildTest-Son","SERIAL_NO":55213,"AGE":"0"},{"DOB":"2014-09-12 00:00:00.0","NameRelation":"FemaleChildTest-Daughter","SERIAL_NO":55216,"AGE":"0"},{"DOB":"2014-09-12 00:00:00.0","NameRelation":"MaleChildTesEmp-Son","SERIAL_NO":55217,"AGE":"0"},{"DOB":"2014-09-12 00:00:00.0","NameRelation":"FemaleChildEmployeeTest-Daughter","SERIAL_NO":55218,"AGE":"0"},{"DOB":"","NameRelation":"Test-Father","SERIAL_NO":55219,"AGE":"0"}]
假设JSON
[{"DOB":"2014-09-03 00:00:00.0","Name":"MaleChildTest","Relation":"Son","SERIAL_NO":55213,"AGE":"0"}....]
在下拉列表中,我希望名称关系作为 "name" 个选项。
<select ng-options="option.serial_no as label(option.Name, option.Relation) for option in fullFamilydetails" ng-model="obj"></select>
在你的 JS 中:
angular.module("SO29137733", [])
.controller("MainCtrl", function ($scope) {
$scope.fullFamilydetails = [{
"DOB": "2014-09-03 00:00:00.0",
"Name": "MaleChildTest",
"Relation": "Son",
"SERIAL_NO": 55213,
"AGE": "0"
}, {
"DOB": "2014-09-03 00:00:00.0",
"Name": "MaleChildTest",
"Relation": "Son",
"SERIAL_NO": 55213,
"AGE": "0"
}];
$scope.label = function (name, relation) {
return name + "-" + relation;
}
});
另一个选项:
<select>
<option ng-repeat="option in options" value="{{option.serial_no}}">
{{option.name + " "+option.relation}}
</option>
</select>
在你的 JS 中:
angular.module("SO29137733", [])
.controller("MainCtrl", function($scope){
$scope.options = [{
serial_no : "123",
name : "hi",
relation: "parent"
},
{
serial_no : "1233",
name : "sa",
relation: "sdf"
}];
})
如果您想将其显示为单对选项,请执行以下操作,
ng-options="option.serial_no as (option.name+' '+ option.relation) for option in fullFamilydetails"
通常我们做的是
...}}_{{$index}}" ng-options="option.serial_no as option.NameRelation for option in fullFamilydetails" ng-model="obj.ch6a_decl_fam_memb_id">
然后 Java 我正在做
...
familyDetails.put("NameRelation", Emp_FamilyInfoTemp.getName()+"-"+Emp_FamilyInfoTemp.getRelation());
}else{
...
如您所见,我在 java 上处理它以将 "NAME" - "RELATION" 对显示为 "name of ng-options"
但我想要的是在 json 中将 NAME 和 RELATION 保留为不同的属性,但在创建 ng-options 时显示它们的组合,我想在保留属性的同时创建相同的效果分开。
当前样本 Json
[{"DOB":"2014-09-03 00:00:00.0","NameRelation":"MaleChildTest-Son","SERIAL_NO":55213,"AGE":"0"},{"DOB":"2014-09-12 00:00:00.0","NameRelation":"FemaleChildTest-Daughter","SERIAL_NO":55216,"AGE":"0"},{"DOB":"2014-09-12 00:00:00.0","NameRelation":"MaleChildTesEmp-Son","SERIAL_NO":55217,"AGE":"0"},{"DOB":"2014-09-12 00:00:00.0","NameRelation":"FemaleChildEmployeeTest-Daughter","SERIAL_NO":55218,"AGE":"0"},{"DOB":"","NameRelation":"Test-Father","SERIAL_NO":55219,"AGE":"0"}]
假设JSON
[{"DOB":"2014-09-03 00:00:00.0","Name":"MaleChildTest","Relation":"Son","SERIAL_NO":55213,"AGE":"0"}....]
在下拉列表中,我希望名称关系作为 "name" 个选项。
<select ng-options="option.serial_no as label(option.Name, option.Relation) for option in fullFamilydetails" ng-model="obj"></select>
在你的 JS 中:
angular.module("SO29137733", [])
.controller("MainCtrl", function ($scope) {
$scope.fullFamilydetails = [{
"DOB": "2014-09-03 00:00:00.0",
"Name": "MaleChildTest",
"Relation": "Son",
"SERIAL_NO": 55213,
"AGE": "0"
}, {
"DOB": "2014-09-03 00:00:00.0",
"Name": "MaleChildTest",
"Relation": "Son",
"SERIAL_NO": 55213,
"AGE": "0"
}];
$scope.label = function (name, relation) {
return name + "-" + relation;
}
});
另一个选项:
<select>
<option ng-repeat="option in options" value="{{option.serial_no}}">
{{option.name + " "+option.relation}}
</option>
</select>
在你的 JS 中:
angular.module("SO29137733", [])
.controller("MainCtrl", function($scope){
$scope.options = [{
serial_no : "123",
name : "hi",
relation: "parent"
},
{
serial_no : "1233",
name : "sa",
relation: "sdf"
}];
})
如果您想将其显示为单对选项,请执行以下操作,
ng-options="option.serial_no as (option.name+' '+ option.relation) for option in fullFamilydetails"