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 –