Jquery Tmpl

编程入门 行业动态 更新时间:2024-10-28 04:23:04
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}}

更多推荐

本文发布于:2023-04-28 08:07:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1331386.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Jquery   Tmpl

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!