Why are JavaScript string arrays interpreted differently by jQuery template {{each}} tags vs. jQuery $.each?

主宰稳场 提交于 2019-12-05 11:46:50

Remember that templates are an implicit loop. Your original {{each}} was looping through each character in each string -- the template was looping through each string in the array.

This will give you the desired result (more or less):

<script id="testTemplate" type="text/x-jquery-tmpl"> 
    <li>
        source[]: ${$data}
    </li>
</script>

http://jsfiddle.net/wuEyp/10/ uses the above code. The index is gone because the template doesn't seem to provide for it at the "root" level.

http://jsfiddle.net/wuEyp/11 will add the indexing back in using a function. For some reason, I can't do it properly with a closure.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!