我想创建一个新的JSON对象(selectedProductAttributes)当第二JSON对象的内容(selectedProductAttributesNames)是针对第3对象compaired所创建( allProductAttributes)!为了更详细地解释我具有低于通过对比另外两个JSON创建JSON对象对象
第一种称为allProductAttributes是包含表单字段
$scope.allProductAttributes = [
{
name: 'postcode',
title: 'Postcode',
required: true,
type: 'text',
max: '10',
placeholder: 'Enter a postcode'
},
{
name: 'Term',
title: 'Contract term',
required: true,
type: 'number',
},
{
name: 'bandwidth',
title: 'bandwidth',
type: 'select',
options: [
{id: 10, name: '10 mb/s'},
{id: 100, name: '100 mb/s'},
{id: 1000, name: '1000 mb/s'},
{id: 10000, name: '10000 mb/s'}
]
},
{
name: 'service',
title: 'Service',
required: true,
}
]
接下来JSON对象,不同的充属性JSON对象一些实例中selectedProductAttributesNames,包含用户想要从allProductAttributes中选择的表单域列表
$scope.selectedProductAttributesNames = [
"postcode",
"service"
]
从上面的例子
所以,当用户请求“邮政编码”和在selectedProductAttributesNames“服务”,应含有从allProductAttributes表单字段属性来创建一个新的JSON对象...
$scope.selectedProductAttributes = [
{
name: 'postcode',
title: 'Postcode',
required: true,
type: 'text',
max: '10',
placeholder: 'Enter a postcode'
},
{
name: 'service',
title: 'Service',
required: true,
}
]
I”对不起,如果我让你困惑。有谁知道我能做到这一点?谢谢
使用'Array.filter'。 – Halcyon 2015-02-09 17:04:31