gpt4 book ai didi

javascript - 是什么让布局在 Marionette.js 中呈现?

转载 作者:行者123 更新时间:2023-11-28 08:12:02 25 4
gpt4 key购买 nike

考虑以下 JS:

var ChildLayout = Marionette.Layout.extend({
template: "... let's not go here ...",
initialize: function() {
console.log('Child Layout Initialized'); // registers once
},
onRender: function() {
console.log('Rendered'); // registers 2 times
},
});

var ParentLayout = Marionette.Layout.extend({
template: "<div class='child-region'></div>",
regions: { childRegion: '.child-region' },
onRender: function() {
console.log('About to initialize ChildLayout'); // registers once
this.childRegion.show(new ChildLayout());
},
});

在上面,我使用 ParentLayout 在其 Regions 之一中渲染 ChildLayout。请注意,我没有将任何类型的模型传递给 ChildLayout

show 函数是 Marionette 的一个属性,逻辑上应该初始化模型,然后渲染模型一次。根据我的理解,Marionette View 不应重新渲染自身,除非其模型发生一些变化。

在我的应用程序中,ChildLayoutonRender 在我的代码中多次触发,尽管它的 initialize 仅触发一次。

我看不到是什么导致 Marionette 多次渲染 ChildLayout - 这没有意义。

有什么见解吗?

编辑

检查时the source code of Marionette.jsshow 函数显然只在初始化之后渲染传递的 View 一次。因此,重新渲染只能在布局自主决定重新渲染时发生。有趣。

最佳答案

事实证明这是我自己的僵尸 View 问题,我已经处理了。

关于javascript - 是什么让布局在 Marionette.js 中呈现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24073405/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com