gpt4 book ai didi

mithril.js - Mithril 只重绘1个模块

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

如果我的页面上有 10 个 m.module,我可以调用 m.startComputationm.endComputation m.redrawm.request 仅用于其中一个模块?

看起来这些中的任何一个都会重绘我的所有模块。

我知道只有 module 1 会受到某些代码的影响,我只想让 mithril 重绘它。

最佳答案

目前,还没有对 Multi-Tenancy 的简单支持(即独立运行多个模块)。

解决方法包括使用子树指令来防止在其他模块上重绘,例如

//helpers
var target
function tenant(id, module) {
return {
controller: module.controller,
view: function(ctrl) {
return target == id ? module.view(ctrl) : {subtree: "retain"}
}
}
}
function local(id, callback) {
return function(e) {
target = id
callback.call(this, e)
}
}

//a module
var MyModule = {
controller: function() {
this.doStuff = function() {alert(1)}
},
view: function() {
return m("button[type=button]", {
onclick: local("MyModule", ctrl.doStuff)
}, "redraw only MyModule")
}
}

//init
m.module(element, tenant("MyModule", MyModule))

你也可以使用类似 this 的东西或 this使用 local

自动装饰事件处理程序

关于mithril.js - Mithril 只重绘1个模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28613387/

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