Side navigation
#8041 closed bug (invalid)
Opened January 24, 2011 08:02PM UTC
Closed January 24, 2011 08:27PM UTC
Last modified January 28, 2011 01:16PM UTC
jquery.tmpl plugin's tmplItem not returning expected item
Reported by: | jdart@dyknow.com | 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
Attachments (0)
Change History (5)
Changed January 24, 2011 08:16PM UTC by comment:1
component: | unfiled → templates |
---|---|
owner: | → BorisMoore |
status: | new → assigned |
Changed January 24, 2011 08:27PM UTC by comment:2
resolution: | → invalid |
---|---|
status: | assigned → closed |
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.
Changed January 24, 2011 09:49PM UTC by comment:3
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?
Changed January 24, 2011 09:58PM UTC by comment:4
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.
Changed January 28, 2011 01:16PM UTC by comment:5
priority: | undecided → low |
---|