Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds $index property to nested templates #33

Closed
wants to merge 1 commit into from

Conversation

clarkbox
Copy link

(similar to the each tag) adds an "$index" property to the data item passed to nested templates using the {{tmpl}} tag
fixes: https://github.com/jquery/jquery-tmpl/issues#issue/28

@clarkbox
Copy link
Author

hmmmm.... $index is only available when an array has been passed to the template. If a dev creates a template to be used against an array AND single object, and does not handle the undefined case (of $index), the template will break.

Should $index always be set?

@BorisMoore
Copy link
Owner

We decided against this feature for the reasons explained here:
http://api.jquery.com/jquery.tmpl/#comment-111707270
http://api.jquery.com/jquery.tmpl/#comment-98013066

Keeping issue 28 open though, to track this request.

@clarkbox
Copy link
Author

you can break the index of an {{each}} the same way as pointed to in above links - by manipulating the dom. but i do get your point. there are differences in the implied ways to use {{tmpl}} and {{each}} tag, it could be much more common to reuse a template and insert in dom without an update().

i admit, it did not occur to me to use the $.inArray approach to get the index from the parent. one problem would be performance in large data sets. i also found in my scenario that i could not use the $.inArray approach, as i was only using templates to setup the initial render, and manipulate the dom from then on - NOT keeping my bound object in sync. but thats just my narrow scenario. I happen to not care about the actual index after initial render as well.

@BorisMoore
Copy link
Owner

Perf is an important aspect too, I agree. I'll be on the lookout for alternatives to address this issue. One way good be to pass the index to the rendered event, so users can easily set index on the item if they want to, in the onRendered handler.

@BorisMoore
Copy link
Owner

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants