Jquery Tmpl - Parent objects property from inside an each loop
I have a json object with a few properties in it including a list of another object type. I then bind the main object to a template using the tmpl plugin and I have an {{each}} for the list. Inside that each I want to get at a property of the original object.
example:
new PageItem(
'Josie',//Name
816,//ItemID
0.0000,//Price
0,//Quantity
-1,//DiscountPrice
'Adopt this bilby!',//Content
ko.observableArray([ //Mods
new ModItem(
'1. Bronze $50', //Name
812, //ItemID
50.0000, //Price
-1//DiscountPrice
),
new ModItem(
'2. Silver $100', //Name
813, //ItemID
100.0000, //Price
-1//DiscountPrice
)
)开发者_运维知识库
Template:
{{each Mods}}
${Name} - ${parentname?}
{{/each}}
Probably makes it a bit trickier when the objects have the same property names...
Figured out the answer. using $data (which is the object applied to the template) I can then get the Parent properties from the each loop.
{{each Mods}}
${Name} - ${$data.Name}
{{/each}}
精彩评论