在 Meteor 中执行 DOM 操作的正确方法是什么? [英] What's the correct way to perform DOM manipulation in Meteor?

查看:38
本文介绍了在 Meteor 中执行 DOM 操作的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个名为 Timeline 的包

I'm using a package called Timeline

https://github.com/VeriteCo/TimelineJS

它的工作原理是有一个占位符,例如

It works by having a placeholder such as

<div id="my-timeline"></div>

然后最终调用 jQuery 来操作 div.在视觉上,我看到时间线出现在屏幕上,然后几乎立即消失.下面这个简单的例子也有类似的效果:

And then ultimately making a jQuery call to manipulate the div. Visually I'm seeing the timeline appear on the screen and then disappearing almost straight away. A similar effect occurs with the following simple example:

<div id="my-temp"></div> 

结合

$(document).ready(function() {
    $('#my-temp').html('HELLO');
});

在不让结果 HTML 消失的情况下执行此类操作的正确方法是什么?

What's the correct way to perform this type of manipulation without having the resultant HTML disappear?

推荐答案

我相信你应该使用 常量区域 以防止 Meteor 重新渲染您的 div.

I believe you should use constant regions to prevent Meteor from re-rendering your div.

{{#constant}}
    <div id="my-temp"></div> 
{{/constant}}

这篇关于在 Meteor 中执行 DOM 操作的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆