@dom
def chart(show: Var[Boolean]) = {
if(show.bind) {
<canvas id="chartCanvas"><canvas>
}
}
如何使用一些图表库初始化画布,例如chartjs
什么时候加载到dom?
解决方案1
@dom
def chart(show: Var[Boolean]) = {
if(show.bind) {
val myCanvas = <canvas id="chartCanvas"><canvas>
myInitializationCode(myCanvas)
myCanvas
} else {
<!-- don't show canvas -->
}
}
解决方案2
您可以创建一个自定义单安装点,并将初始化代码放入重写中mount
method:
val yourCustomMountPoint = new SingleMountPoint[Boolean](show) {
override def mount() = {
super.mount()
// Your custom initialization code
}
override def unmount() = {
// Your custom clean up code
super.unmount()
}
override def set(newValue: Boolean) = {
// Your custom handler when `show` get changed
}
}
// Inject your custom mount point into the rendering process
yourCustomMountPoint.bind
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)