创建元素后如何在聚合物中调用函数(如jquery中的ready函数) [英] how to call a function in polymer after the elements have been created (like ready function in jquery)
问题描述
我正在尝试编写一个与DOM相关的函数,但是问题是,polymer在DOM加载之前调用了该函数,并且正如预期的那样,它给了我一个未定义的错误!
I'm trying to write a function, which is related to the DOM, but the problem is , polymer calls the function before the DOM is loaded, and as expected it gives me an undefined error!
我一直在寻找类似onComplete之类的事件,以便它可以在加载DOM后读取我的函数.
I was looking for an event like onComplete or anything like this, so that It could read my function after loading the DOM.
***最好的例子是Jquery中的ready函数
*** the best example is ready function in Jquery
P.S:聚合物中的就绪:"事件无法正常工作,
P.S : "ready:" event in polymer doesn't work properly,
推荐答案
在Polymer 2.0中,您可以将其用于connectedCalback生命周期方法:
In Polymer 2.0 you can use this into connectedCalback life cycle method:
connectedCallback(){
super.connectedCallback();
Polymer.RenderStatus.beforeNextRender(this, function() {
// All references to the dom elements into the web component
// [...]
});
}
这篇关于创建元素后如何在聚合物中调用函数(如jquery中的ready函数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!