BorisMoore / jquery-tmpl

The original official jQuery Templates plugin. This project was maintained by the jQuery team as an official jQuery plugin. It is no longer in active development, and has been superseded by JsRender.
3.23k stars 1.01k forks source link

Patch to fix "Uncaught TypeError: Cannot call method 'push' of undefined" jquery.tmpl.js:429 #117

Closed zavulon closed 13 years ago

zavulon commented 13 years ago

Line 426 should be relpaced from

while ( pntItem && pntItem.key != pntNode ) {

to

while ( pntItem.nodes && pntItem.key != pntNode ) {

BorisMoore commented 13 years ago

The only tmplItem that does not have a nodes property is the topTmplItem, which has key 0. The second condition should prevent entering the if block, in that case, since pntNode will be zero. Can you provide a test case in which that type error occurred?

BorisMoore commented 13 years ago

Closing, since no reply to request for test case...

nobuf commented 13 years ago

The below code gets "Uncaught TypeError: Cannot call method 'push' of undefined" jquery.tmpl.js:429 But once I replace 'a' element to span or div on #testTmpl then it works peacefully.

Chrome14/Firefox6.0

<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="https://raw.github.com/nanzhi/jquery-tmpl/master/jquery.tmpl.js"></script>

<script id="test2Tmpl" type="text/x-jquery-tmpl">
    <div>
        <a>test</a>
    </div>
</script>
<script id="testTmpl" type="text/x-jquery-tmpl">
    <a>
    {{tmpl() "#test2Tmpl"}}
    </a>
</script>

<script>
$(document).ready(function(){
    $('#testTmpl').tmpl().appendTo('body');
});
</script>
</body>
catamphetamine commented 12 years ago

I'm also having this issue. Removing "a" tag from subtemplate removes the error, but we need "a" tag in the subtemplate.