GithubHelp home page GithubHelp logo

Comments (6)

polgfred avatar polgfred commented on June 19, 2024

Can you try a key other than class? class is technically a reserved word in JavaScript.

-Fred

--Science answers questions; philosophy questions answers.

On Tuesday, August 30, 2011 at 4:09 AM, jangingnicht wrote:

hi,
i am having trouble with using the jquery tmpl engine via the $.View call. consider the following call:
$.View("//test/views/test.tmpl",{heads:[{class: "h1", mes: "Ping"}, {class: "h2", mes: "Pong"}]})

if test.tmpl look like this

{{each heads}}
<h1>${mes}</h1>
{{/each}}

it returns correctly <h1>Ping</h1> <h1>Pong</h1>

if test tmpl looks like this:

{{each heads}}
<h1 class="${class}">${mes}</h1>
{{/each}}

undefined is returned whereas i would expect <h1 class="h1">Ping</h1> <h1 class="h2">Pong</h1>

I just checked out the latest version of jquerymx and tested in Firefox 6.0

Reply to this email directly or view it on GitHub:
#57

from jquerymx.

jan--f avatar jan--f commented on June 19, 2024

ups..yeah my mistake...you are right. stupid of me but some kind of error message would be nice if possible at all.
thanks
edit
it looks like it should be working regardless
https://developer.mozilla.org/en/JavaScript/Reference/reserved_words#Reserved_word_usage
not sure though if the issue is in tmpl or jquerymx
will test the same with bare $.tmpl

from jquerymx.

jan--f avatar jan--f commented on June 19, 2024

yeah so it turns out jquery.tmpl has hickups with reserved words as IdentifierNames
$.tmpl("{{each heads}}<h1 class='${class}'>${mes}</h1>{{/each}}",{heads:[{class: "h1", mes: "Ping"}, {class: "h2", mes: "Pong"}]}) produces an error, whereass $.tmpl("{{each heads}}<h1 class='${foo}'>${mes}</h1>{{/each}}",{heads:[{foo: "h1", mes: "Ping"}, {foo: "h2", mes: "Pong"}]}) works fine

from jquerymx.

polgfred avatar polgfred commented on June 19, 2024

It's not that simple. While it may be technically legal as a key in an object literal, when the template gets compiled, your reference to "class" will be a variable, which is not legal. Additionally, your mileage may vary from browser to browser. Best to just avoid them.

from jquerymx.

jan--f avatar jan--f commented on June 19, 2024

yeah you are right...best avoid it.
Apparently it is possible though if ${$data["class"]} is used...
http://api.jquery.com/jquery.tmpl/#comment-148052151

from jquerymx.

polgfred avatar polgfred commented on June 19, 2024

Yes because in this case "class" is just a string, not an identifier.

--Science answers questions; philosophy questions answers.

On Tuesday, August 30, 2011 at 10:01 AM, jangingnicht wrote:

yeah you are right...best avoid it.
Apparently it is possible though if ${$data["class"]} is used...
http://api.jquery.com/jquery.tmpl/#comment-148052151

Reply to this email directly or view it on GitHub:
#57 (comment)

from jquerymx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.