gpt4 book ai didi

jquery - 如何将数据附加到 jquery tmpl

转载 作者:行者123 更新时间:2023-12-03 22:56:57 27 4
gpt4 key购买 nike

有人知道如何将用于渲染 jQuery 模板的数据项附加到生成的 dom 对象吗?

给定这个 tmpl:

<script id="sectionTemplate" type="text/x-jquery-tmpl">
<div class="story-writer-section sticker ${CssClasses}">
<div class="title">
<div class="delete-button sticker-button"/>
${SectionName}
</div>
<div class="story-writer-story-container">
</div>
</div>

还有这个:

    $("#sectionTemplate")
.tmpl(sections)
.appendTo(".story-writer-section-container");

我想通过 .data('section', data) 将每个部分附加到结果中,以便稍后可以访问所有数据,因为并非所有数据都被渲染,例如我需要的 id 等稍后在执行删除等操作时再进行操作。

也许是这样的......

        $("#sectionTemplate")
.tmpl(sections)
.appendTo(".story-writer-section-container").each(function (????) {
this.data('section', ?????);
});

但我不知道如何获取用于渲染此 tmpl 的当前数据项。

也许有办法将其包含在模板本身中?

非常感谢任何帮助。

最佳答案

好的,我已经解决了。看起来数据已经添加到 .tmpl() 生成的元素中,并且可以像这样访问:

$.tmplItem(this).data

非常好,像往常一样,jQuery 不会让人失望。

关于jquery - 如何将数据附加到 jquery tmpl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4344550/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com