0
让我们假设我们有一个防暴SPA这样的:RiotJS 3:调用标签功能
的index.html:
<my-tag></my-tag>
<script type="riot/tag" src="my-tag.riot"></script>
<script>
//OK we need a compile() wrapper to access all tag instances
var tags;
riot.compile(function() {
tags = riot.mount('*');
});
</script>
我-tag.riot:
<my-tag>
<p>My tag</p>
<script>
myFunction(){
console.log('doing stuff...')
}
</script>
</my-tag>
我想从index.html调用myFunction()。从理论上讲它可能是这样的:
riot.compile(function() {
tags = riot.mount('*');
});
tags[0].myFunction();
事实上标签阵列编译()包装 之外不可用。当然,可以从compile()内部调用myFunction():
riot.compile(function() {
tags = riot.mount('*');
tags[0].myFunction();
});
但我不确定这是一个好方法。那么访问内嵌标签功能的最佳做法是什么?提前致谢!
上plunker同样的问题: http://plnkr.co/2G3ReNBCpgCSgDZc1f9O –