0

I have a couple Javascript functions which concatenates a URL which I set to the variable c. I then try to pass that variable into jQote2:

$.get("emptyReq.tpl", function(tmpl,c) {
  $("#reqs").jqoteapp(tmpl, result, c);
});

In emptyReq.tmpl, I'm doing the following:

<tr id="row">
  <td name="id" class="id"><a href="<%=this.c%>"><%= this.FormattedID %></a></td>
  <td name="name" class="name"><%= this._refObjectName %></td>
  <td name="state" class="state"><%= this.ScheduleState %></td>
  <td name="owner" class="owner"></td>
</tr>

I've tried a couple of variations (this.c and c) and I've also tried different variables, but I'm not able to get the URL to display correctly.

c is labeled as undefined in the console, and the URL ends up being something like: http://127.0.0.1/xampp/py2/undefined instead of the actual c which is something like https://rally1.rallydev.com/slm/rally.sp#/2735190513d/detail/userstory/4599269614

Is there a way to pass the parameters properly? Or am I supposed to do the concatenation in the .tmpl file itself?

Here is what I've been using as a reference: jQote Reference.

4

1 回答 1

0

里希玛哈拉吉,

jqoteapp方法的第三个参数用于<% ... %>在每次调用的基础上更改模板标签(默认情况下)。如果您需要将其他数据传递给您的模板,您有两种选择:

  1. c创建一个全局变量(不过我不建议这样做)
  2. c的值复制到data参数(推荐):

    请注意,复制需要考虑到您的模板数据是什么类型,即处理单个对象与对象数组不同!

    $.get("emptyReq.tpl", function(tmpl,c) {
        var data;
    
        // 'result' seems to be a global var, thus making a copy is a good idea.
        // Copying needs to take into account the type of 'result'
    
        if ( Object.prototype.toString(result) === '[object Array]' ) {
            data = result.slice(0);
        } else {
            data = [$.extend({}, result)];
        }
    
        // Now it is safe to add 'c' to the wrapping array. This way
        // we won't override any homonymous property
        data.c = c;
    
        // Call the processing with our local copy
        $("#reqs").jqoteapp(tmpl, data);
    });
    

    更改此设置后,您将能够c通过模板 lamda 的固有属性进行访问data

    <tr id="row">
        ... <a href="<%= data.c %>"><%= this.FormattedID ...
    </tr>
    

问候,
aefxx

于 2011-11-24T09:26:18.457 回答