Use return value in jQuery template

After some clarification, I will repeat my question as follows.

In jquery template I have sth. how to use it to use the return value of a function

 <p class="hidden">${$data.score = getScore(results)}</p> {{tmpl(homeTeam, {score: score}) "#scoreTemplate"}} 

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

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

Many thanks,
Robson

+6
source share
1 answer

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 syntax score: d = getScoreByMatch($data, true) will work in javascript.

I just introduced a variable to get the result from the getScoreByMatch() method, and then assign that value to the variable to the score property.

I'm not sure if this will work or not, but just try and see.

+1
source

Source: https://habr.com/ru/post/891549/


All Articles