2011-05-24 26 views
1

我有一個模板,如下如何調用jQuery的模板函數返回值

<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> 
以上

${status()}調用函數狀態返回這樣

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

我的問題是我的字符串hav從狀態函數被調用的模板發送一個值... .. like值​​...

所有在模板中的值,如${priority}${hours}等被綁定到一個PageMethod的模板......

需要一個解決方案

回答

2

您可以使用關鍵字$data從數據值傳遞給函數。更改模板下面一行是這樣的:

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

  • 假設 'action_status' 從您的數據正確的屬性名稱...

更新:這裏的link to the api。查看「評估表達式和函數」部分

+0

yes action_status is right ..im tryin what you hav says – bhargav 2011-05-24 14:08:32

+0

thanx shane that really works ..i hav has been serching for this since 4 hr ..im jus started with templates – bhargav 2011-05-24 14:13:52

+0

沒問題...模板很棒,不是嗎?只需保持該API的鏈接方便...;) – ShaneBlake 2011-05-24 14:15:16