简体   繁体   English

标签内的jsRender模板

[英]jsRender template inside tag

I am trying to put a jsRender-template inside a tag. 我试图将jsRender-template放在标签内。
I need this to be able to render similar onmouseover and onmouseout into any element. 我需要它能够将类似的onmouseoveronmouseout渲染到任何元素中。

Test code: 测试代码:

inside template 内部模板

<small {{for "Key_" + Key tmpl="tooltip_logic"/}}>shows key on hover</small>

partial template 部分模板

<script type="text/x-jsrender" id="tooltip-logic-template">
    onmouseover="$('#Key_{{:#data}}').show();" onmouseout="$('#Key_{{:#data}}').hide();"
</script>

javascript before rendering template 呈现模板之前的javascript

$.templates({ 
    ...
    tooltip_logic: $('#tooltip-logic-template').html() 
});

The output gets render inside the <small> tag though. 输出会呈现 <small>标签虽然。

Is there any way to achieve this? 有什么办法可以做到这一点? And if not, what is the closest approach possible? 如果没有,最接近的方法是什么?

There are a couple of sample pages on jsviews.com that look at this scenario. jsviews.com上有几个示例页面,介绍了这种情况。

First, this "From rendering to linking" page shows how you can indeed use JsRender tags within the HTML markup of an element. 首先,此“从渲染到链接”页面显示了如何在元素的HTML标记内使用JsRender标签。 It then goes from there towards how you can do the same thing in the context of JsViews and data-linking. 然后从那里开始,到如何在JsViews和数据链接的上下文中执行相同的操作。

Later in the tutorial, on the page: "Using data-link and visibility, with mouse events (hover)" , it explores alternative ways hook up the onmouseover behavior and showing/hiding a related HTML element. 在本教程后面的页面: “使用数据链接和可见性,并带有鼠标事件(悬停)” ,它探讨了挂钩onmouseover行为以及显示/隐藏相关HTML元素的替代方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM