Enyo 中创建函数和渲染函数之间的场景差异

Scenario difference between create and rendered function in Enyo

本文关键字:函数 之间 创建 Enyo      更新时间:2023-09-26

我在解决问题时遇到了这种情况。考虑以下情况,提供jsfiddle链接:

http://jsfiddle.net/fp5Lt7zx/1/

enyo.kind({
name:'base',
components:[
    {name:'button', kind:'moon.Button'}
],
create: function(){
    this.inherited(arguments);
    this.$.button.createComponent({
        name:'tag',
        classes:'list-recording-tag',
        components: [{
                content: "NEW",
                classes: "list-recording-tag-font"
        }]
    });
}
});
new base().renderInto(document.body);

这工作正常,但是当我不编写 create 中给出的功能,而是尝试在渲染函数中提供它时,问题就来了。以下是具有相同功能的渲染函数的链接。

http://jsfiddle.net/esoyhrh7/

使用渲染函数,动态创建的"标签"组件将不会呈现。所以为了有力地渲染,我不得不添加这行代码

this.$.button.$.tag.render(); //this way is not recommended though

为什么需要在渲染函数中强制渲染标签组件,而不是在创建函数中。除此之外,它们之间还需要考虑哪些差异?

如果将

控件添加到已呈现的控件中(就像将其放入呈现函数时所做的那样),则必须强制浏览器重绘,因此需要在新控件上调用 .render()。 如果将其保留在 create 中,则在呈现其包含控件之前构造组件,因此在呈现时将存在。