Jquery Tmpl - 父对象属性来自每个循环内部(Jquery Tmpl - Parent objects property from inside an each loop)
我有一个json对象,其中包含一些属性,包括另一个对象类型的列表。 然后我使用tmpl插件将主对象绑定到模板,我有一个{{each}}列表。 在每个我希望获得原始对象的属性。
例:
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 ) )模板:
{{each Mods}} ${Name} - ${parentname?} {{/each}}当对象具有相同的属性名称时,可能会使它变得有点棘手......
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...
最满意答案
想出答案。 使用$ data(这是应用于模板的对象)然后我可以从每个循环中获取Parent属性。
{{each Mods}} ${Name} - ${$data.Name} {{/each}}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}}更多推荐
发布评论