JQuery Tmpl - property of parent objects from within each loop

I have a json object with several properties in it, including a list of another type of object. Then I associate the main object with the template using the tmpl plugin, and I have {{each}} for the list. Inside each of them I want to get 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}} 

This is probably a little more complicated if the objects have the same property names ...

+4
source share
1 answer

Figured out the answer. using $ data (which is the object applied to the template), I can get the properties of the parent from each loop.

 {{each Mods}} ${Name} - ${$data.Name} {{/each}} 
+5
source

Source: https://habr.com/ru/post/1344026/


All Articles