Ember JS 2对HTML的更改在重新渲染后被删除
Ember 2. I have a template where I display my model data. And I have a JS script that makes some changes to HTML (inits some JQuery plugins etc), and I need to run it every time I render the view.
Ember 2.我有一个模板,用于显示模型数据。我有一个JS脚本对HTML进行了一些更改(在一些JQuery插件中等),每次渲染视图时我都需要运行它。
I trigger it in the didRender hook of my view. It works fine on the first load. But when I visit the page second time, I can see that plugins are initializing, but in the next moment all changes disappear and the page is as it was initially in the template.
我在我的视图的didRender钩子中触发它。它在第一次加载时工作正常。但是当我第二次访问该页面时,我可以看到插件正在初始化,但是在下一刻,所有更改都会消失,页面就像最初在模板中一样。
I guess that there is something that looks for changes in the model and re-render the page after it was rendered in the second time, but I'm not sure about it. I tried to listen for other hooks, like didUpdate, but they are not triggering.
我猜有些东西可以在模型中查找更改并在第二次渲染后重新渲染页面,但我不确定。我试图听取其他钩子,比如didUpdate,但它们没有触发。
What could be a reason of such strange behaviour?
这种奇怪行为可能是什么原因?
A simple example: Js:
一个简单的例子:Js:
App.ResumeView = Ember.Component.extend({
didRender: function () {
$('.event h6').text('Hi!');
},
didUpdate: function () {
$('.event h6').text('Hi!');
}
});
Hbs:
{{#each model.work as |work|}}
<div class="event">
<h4>{{work.position}}</h4>
<h5>{{work.name}}</h5>
<h6></h6>
<span class="location">{{work.location}}</span>
<p>{{work.description}}</p>
</div>
{{/each}}
Result: on the first load all H6s say 'hi', then if I go to another page and return to this, it shows 'hi' for a second and then it disappears.
结果:在第一次加载时,所有H6都说'hi',然后如果我转到另一页并返回到此,它会显示'hi'一秒钟然后它就会消失。
1 个解决方案
#1
0
I'm going to bet the problem is because the plugins have initialized already, they aren't initializing again. Try tearing down your jQuery plugins in the willDestroyElement
event.
我打赌这个问题是因为插件已经初始化,它们没有再次初始化。尝试在willDestroyElement事件中拆除jQuery插件。
更多相关文章
- 关于JavaScript变量声明及其初始化的问题
- jQuery插件:如何将元素引用传递给回调函数?
- 可编辑的jquery表格插件
- BootStrap3.0学习--JavaScript 插件
- jQuery分页插件jBootstrapPage,一个Bootstrap风格的分页插件
- Cordova相机插件ios11无法从库中选取图像
- javascript适合移动端的响应式瀑布流插件实例演示
- Angular使用jQuery插件与外部控制器中的对象
- 在QGIS下开发python插件