gpt4 book ai didi

templates - backbone/marionette 将 HTML 附加到区域中

转载 作者:行者123 更新时间:2023-12-02 05:01:48 25 4
gpt4 key购买 nike

我开始在现有主干应用程序中使用 Marionette。我有一些 HTML,我想将其附加到一个区域中。在纯粹的主干中,我可以只做 this.$el.append(html_code) 就可以了。据我所知, Marionette 区域只允许对 View 进行操作(必须实现 render 方法)。在 Marionette 区域调用 append 会引发“未定义方法”错误。

是否可以将纯 HTML 附加到 Marionette 区域?

最佳答案

不,不可能将纯 html 注入(inject) Marionette.Region

理论上,您可以使用 someRegion.elsomeRegion.getElement() 访问区域 DOM 元素,但这必须在呈现之后完成(至少不是可能在具有标准行为的 Marionette.View 中)。

但是您可以通过使用特制的Marionette.ItemView 来达到预期的效果:

@someRegion.show(new Marionette.ItemView({template: '<h1>gach</h1>'}));

您也许还应该看看 Marionette.Renderer .

关于templates - backbone/marionette 将 HTML 附加到区域中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16947458/

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