#8041 closed bug (invalid)
jquery.tmpl plugin's tmplItem not returning expected item
Reported by: | Owned by: | BorisMoore | |
---|---|---|---|
Priority: | low | Milestone: | 1.next |
Component: | templates | Version: | 1.4.4 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
If you render a template using an each and then access the dom item (for example in a live/delegate event handler) tmplItem returns the parent data structure as opposed to the desired item in the array:
//returns { items: [ {num: 1} ] } //instead of { num: 1 }
See http://jsfiddle.net/cKA3s/2/ Ideally, items inside of {{each}} should be considered nested templates
Change History (5)
comment:1 Changed 12 years ago by
Component: | unfiled → templates |
---|---|
Owner: | set to BorisMoore |
Status: | new → assigned |
comment:2 Changed 12 years ago by
Resolution: | → invalid |
---|---|
Status: | assigned → closed |
comment:3 Changed 12 years ago by
Thanks for the note on tmpl. Unfortunately, tmpl does not have access to $index in the same way {{each}} does, or at least not in my testing. Is there a way to access index or would this have to be a plugin to the templating system to create a hybrid of the two tags?
comment:4 Changed 12 years ago by
There are a few ways you can work with index in nested templates. See https://github.com/jquery/jquery-tmpl/issues#issue/28 and http://bugs.jquery.com/ticket/7137 on reasons why it is not exposed, and some suggested approaches. Also status on whether that feature may later be added to jquery-templates.
comment:5 Changed 12 years ago by
Priority: | undecided → low |
---|
This is by design.
Under container2 there is only one rendered template instance. {{each}} does not create new nested template instances.
The feature you suggest is already available though, if you want it. Just replace {{each items}} by {{tmpl(items) "#tmpl3"}} with tmpl3 using the content you currently have within the {{each}} tag - <li>${ num }</li>.
{{tmpl}} is for template composition. {{each}} is for iteration within a template without creating sub-templates.