2016-11-30 4 views
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> 

I을 index.html에서 myFunction()을 호출하려고합니다.

riot.compile(function() { 
    tags = riot.mount('*'); 
    }); 
tags[0].myFunction(); 

사실 태그 배열이 컴파일() 래퍼 밖에 사용할 수 없습니다 : 이론적으로는 이런 일이 될 수 있습니다. 물론 컴파일() 내부에서 myFunction()을 호출 할 수 있습니다.

하지만 잘 접근 할 수는 없습니다. 따라서 인 태그 함수에 액세스하는 가장 좋은 방법은 무엇입니까? 미리 감사드립니다!

+0

플 런커 (plunker)에 관한 동일한 문제 : http://plnkr.co/2G3ReNBCpgCSgDZc1f9O –

답변

0

변수를 전역으로 정의하고 컴파일 콜백 내에 값을 할당하십시오.