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 simpli开发者_C百科fied - like the following, which unfortunately doesn't do the trick?
{{tmpl(homeTeam, {score: getScore(results)}) "#scoreTemplate"}}
Many thanks,
RobsonTry 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.
精彩评论