SunnyRed
SunnyRed

Reputation: 3545

Use a return value in a jQuery template

After some clarification I restate my question as follows.

In a jquery template I've got sth. messy like this to use a return value of a function

<p class="hidden">${$data.score = getScore(results)}</p>

{{tmpl(homeTeam, {score: score}) "#scoreTemplate"}}

Can this be simplified - like the following, which unfortunately doesn't do the trick?

{{tmpl(homeTeam, {score: getScore(results)}) "#scoreTemplate"}}

Many thanks,
Robson

Upvotes: 6

Views: 366

Answers (1)

user405398
user405398

Reputation:

Try something like this,

{{tmpl(
homeTeam, 
{
     teamRole: 'homeTeam', 
     score: d = getScoreByMatch($data, true)
}
) "#scoreTemplate"}}

OR

{{tmpl(
roadTeam, 
{
    teamRole: 'roadTeam', 
    score: d = ${getScoreByMatch($data, false)}
}
) "#scoreTemplate"}}

I have never worked with jquery templates. But this score: d = getScoreByMatch($data, true) syntax will work in javascript.

What i did is just introduced a variable to get the result from getScoreByMatch() method and then assigning that variable's value to the score property.

I am not sure about it will work or not, but just give a try and see.

Upvotes: 1

Related Questions