Answer the question
In order to leave comments, you need to log in
How do I get the index of an array being processed in jQuery.tmpl and why can't I retrieve an object property?
Good afternoon.
I'm trying to get an index in an array processed by the template. First of all, I tried to create a variable before the template by implementing the index method:
var i=1;<br>
$('#trackTmpl').tmpl(data, {<br>
index: function() {<br>
return i++;<br>
}<br>
});<br>
$('#trackTmpl').tmpl(data, {<br>
index: function() {<br>
console.log(this);<br>
console.log(this.key); //undefined<br>
return this.key; //undefined<br>
}<br>
});<br>
${$item.key}
${console.log($item)}
Answer the question
In order to leave comments, you need to log in
There is no chrome under the other, but it seems to me that they have the same principle with ff:
var obj = {}
console.log(obj)
obj.q = 2;
console.log(obj)
object {} Object {q=2}
And what did the native syntax not please (pass an array to the template)?
{{each(key, item) items}}{{/each}}
Very similar to the problem of closures - javascript.ru/basic/closure
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question