如何将额外的变量和参数传递给jQote2?

发布于 2024-12-14 23:48:11 字数 1207 浏览 1 评论 0原文

我有几个 Javascript 函数,它们连接一个 URL,我将其设置为变量 c。然后,我尝试将该变量传递到 jQote2:

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

在emptyReq.tmpl 中,我正在执行以下操作:

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

我尝试了几种变体(this.c 和 c),并且我也尝试了不同的变量,但我无法正确显示 URL。

c 在控制台中被标记为未定义,并且 URL 最终类似于: http://127.0.0.1/xampp/py2/undefined 而不是实际的 c ,类似于 https://rally1.rallydev.com/slm/rally.sp# /2735190513d/detail/userstory/4599269614

有办法通过吗参数正确吗?或者我应该在 .tmpl 文件本身中进行串联?

以下是我一直用作参考的内容:jQote 参考

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

原来分手还会想你 2024-12-21 23:48:11

rishimaharaj,

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

  1. c 设为全局变量(不过我不建议这样做)
  2. 复制 c' data 参数的 s 值(推荐):

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

    $.get("emptyReq.tpl", function(tmpl,c) {
        变量数据;
    
        // 'result' 似乎是一个全局变量,因此制作一个副本是一个好主意。
        // 复制需要考虑“结果”的类型
    
        if ( Object.prototype.toString(result) === '[对象数组]' ) {
            数据 = 结果.slice(0);
        } 别的 {
            数据 = [$.extend({}, 结果)];
        }
    
        // 现在可以安全地将“c”添加到包装数组中。这边走
        // 我们不会覆盖任何同名属性
        数据.c = c;
    
        // 使用我们的本地副本调用处理
        $("#reqs").jqoteapp(tmpl, 数据);
    });
    

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

    
        ... <%= this.FormattedID ...
    
    

问候,
埃夫克斯

rishimaharaj,

the jqoteapp method's third paramter is used to change the template tag (<% ... %> by default) on a per call basis. If you need to pass additional data to your template you have two options:

  1. Make c a global variable (I wouldn't recommend that, though)
  2. Copy c's value to the data parameter (recommended):

    Please be aware that the copying needs to take into account of what type your
    templating data is, i.e. a single object is handled different from an array of
    objects!

    $.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);
    });
    

    Once you've changed this, you will be able to access c through the templating
    lamda's inherent property data:

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

Regards,
aefxx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文