我遇到的问题是下面的数据结构是我试图在模板中呈现的内容。只有从返回数据的函数返回一个数组元素时,它才有效。
我有一个对象数组数组,就像这样(每个数组元素只有一个对象):
[ [],
[],
[],
[],
[],
[],
[],
[],
[
{
businessDetails: { companyName: 'Companyname' },
address:
{ firstName: 'firstname',
lastName: 'last name',
addressLineOne: 'address line one',
addressLineTwo: 'address line two',
city: 'city',
postCode: 'postcode',
email: 'email',
phoneNumber: '123456879',
mobileNumber: '123456789'
},
paymentDetails: { paypalEmail: 'email' },
createdBy: 'jERFPGRv6oPTFqjWb',
_id: 'LrqDm5LJcBpo5wW7W'
}
]
]
这样的结构是这样创建的:
var businesses=[];
for(var i=0; i<recs.length; i++){
businesses[i] = BusinessDetails.find({createdBy: recs[i].BusinessDetailsId}).fetch();
}
//this works and the data in this element is rendered as expected
return businesses[0];
//this doesn't render anything
return businesses;
如果只传递一个数组元素,模板的这一部分就可以工作。
{{#each businesses}}
createdBy: {{createdBy}}
{{#with businessDetails}}
{{companyName}}
{{/with}}
{{/each}}
有人可以建议我应该如何呈现上面的数据结构吗?
答案 0 :(得分:1)
你有一个数组数组。如果这是您想要的数据结构,那么您需要each
内的each
,如下所示:
{{#each businesses}}
{{#each this}}
createdBy: {{createdBy}}
{{#with businessDetails}}
{{companyName}}
{{/with}}
{{/each}}
{{/each}}