에서 아이 템플릿의 통화 기능 내가 AVEC 아이 템플릿 Content
만 버튼이있는 부모 템플릿 Container
있는 경우 : callback
에 함수를 전달할 수있는 경우유성, 부모 템플릿
<head>
<title>test</title>
</head>
<body>
{{> Container}}
</body>
<template name="Container">
{{# Content callback = callBack }}
<button>ok</button>
{{/Content}}
</template>
<template name="Content">
{{> UI.contentBlock}}
</template>
합니다. 이와 같이 :
Template.Container.helpers({
callBack: function() {
return function() {
console.log('this is my callback');
}
}
});
그래서 내 콘텐츠 템플릿에서 부모 템플릿의 함수를 호출 할 수 있습니다. 예를 들면 다음과 같습니다.
Template.Content.events({
'click button': function (e, tmpl) {
tmpl.data.callback();
}
});
하지만 때로는 다른 방식으로 처리해야합니다. 자식이 함수를 호출하는 부모. 그것을하는 당신의 방법은 무엇입니까?
편집 :
내가 행동과 포크로 쉽게 만드는을 보여주기 위해 meteorpad에 저장된 : 더 선호 같이 유성과 내 경험을 바탕으로 http://meteorpad.com/pad/48NvCFExxW5roB34N/test-pass-callback-to-parent
이벤트 이미 터를 위와 같이 자식 템플릿에 전달하기 전에 템플릿 간의 통신에 [이벤트 이미 터] (https://github.com/Olical/EventEmitter)를 사용했습니다. 아주 잘 작동합니다. 자식 템플릿은 부모 템플릿에서 수신 할 이벤트를 방출 할 수도 있습니다. – nephets