Pregunta

I am trying to use Tempo.js for templating, The documents are sparse. Please try to do it in SO, not jsFiddle.

 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    <head>

            <script type="text/javascript" src="https://raw.github.com/twigkit/tempo/master/tempo.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>


        <script type="text/javascript" charset="utf-8">

            var data = [
                    {'name':{'first':'Leonard','last':'Marx'},'nickname':'Chico','born':'March 21, 1887','actor': true,'solo_endeavours':[{'title':'Papa Romani'}]},
                    {'name':{'first':'Adolph','last':'Marx'},'nickname':'Harpo','born':'November 23, 1888','actor':true,'solo_endeavours':[{'title':'Too Many Kisses','rating':'favourite'},{'title':'Stage Door Canteen'}]},
                    {'name':{'first':'Julius Henry','last':'Marx'},'nickname':'Groucho','born': 'October 2, 1890','actor':true,'solo_endeavours':[{'title':'Copacabana'},{'title':'Mr. Music','rating':'favourite'},{'title':'Double Dynamite'}]},
                    {'name':{'first':'Milton','last':'Marx'},'nickname':'Gummo','born':'October 23, 1892'},
                    {'name':{'first':'Herbert','last':'Marx'},'nickname':'Zeppo','born':'February 25, 1901','actor':true,'solo_endeavours':[{'title':'A Kiss in the Dark'}]}
                ];

            Tempo.prepare('marx-brothers').render(data);

        </script>       

    </head>
    <body>

    <ol id="marx-brothers">
        <li data-template>{{nickname}} {{name.last}}</li>
    </ol>

    </body>
</html>
¿Fue útil?

Solución

You're trying to run the Tempo.prepare call before the DOM with the ID it references has loaded.

Either put the script tag right before the </body> closing tag, or wait until the DOM's ready before running the code, using something window.onload or jQuery's $(document).ready(...) pattern.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top