Search code examples
asp.netjquery-templates

how to call a function returning value in jquery template


i have a template as below

<script id="ActionTemplate" type="text/x-jquery-tmpl">     
  <tr>
    <td> <a href="#" OnClick="setActionId(${action_id}, ${project_id}, ${merchant_id}, ${channel_id}, ${customer_id})" >${action_id}</a></td> 
    <td>${priority} </td>
    <td>${date_to_display} </td> 
    <td> ${date_from}</td> 
    <td>${action_title} </td>      
    <td> ${status()} (${percentage_completed}%)</td> 
    <td> ${hours}</td> 
    <td>${contactFrom} </td>
    <td>${contactTo} </td> 
  </tr>
</script>

in above ${status()} calls the function status which returns a string like this

<script type="language/javascript">
  function status(){
    return "some_string";
  }
</script>

my problem is i hav to send a value from template where the status function is called..value like ${action_status}...

all the values that are in the template like ${priority},${hours},etc are binded to template in a pagemethod...

need a solution


Solution

  • You can pass values from your data to function using the $data keyword. Change the following line in your template like this :

    <td> ${status($data.action_status)} (${percentage_completed}%)</td>

    • assuming 'action_status' is the correct property name from your data...

    Update: Here's the link to the api. Look down for the section "Evaluating Expressions and Functions"