I have a collection that has within it an object that holds an array of yet more objects that need to be unpacked to display in a template eventually.
The item in the sub-object is an order, and the order contains an array of line items.
I can get the order out fine, and see the array of line items no problem, but that's where I come unstuck.
I thought the following would work (using js to convert them into an array of strings to then display somehow)
Template.editEvent.helpers({
lineItems: function(req) {
var order = req.order;
console.log(order);
var lines;
var count = 1;
_.each(order, function(item) {
var string;
string +count++ + '. ';
if(item.age) { // we have a cloathing string
string += item.age + " " + item.sex + " " + item.Season + " " + "Number: " + item.Number;
lines.push(string);
}
else if(item.pushers) {
string += "Pushers needed: " + item.pushers;
lines.push(string);
}
else if(item.cots) {
string += "Cots needed: " + item.pushers;
lines.push(string);
}
else if(items.extra) {
string = "Extra info: " + item.extra;
lines.push(string);
}
else {
string = "Don't know this field";
lines.push(string);
}
console.log(lines);
});
return lines;
}
})
Where the tests are to see if the line item starts with the field shown (because the line items can be different).
However, the _.each is throwing up on the client, (it works fine in the startup code, so I guess from that its server only?)
Am I barking up the wrong tree here, should this embedded object be a new collection? If I am right, how do I go about displaying the returned string array (only just thought of this) in the template anway?
lines. usevar lines = []; also, what is:string +count++ + '. '? did you meanstring += count++ + '. '? If so then you also need to initializestring(e.g.,= "").