Meteor模板访问子模板辅助函数

Meteor模板访问子模板辅助函数,meteor,meteor-blaze,Meteor,Meteor Blaze,父Meteor模板是否可以直接访问子模板?理想情况下,我希望使用带有API的小部件模板。我希望有这样的事情: mypage.html <template name="myPage"> <div class="widgetContainer"></div> <button>submit</button> </template> 上述操作不起作用,因为myWidgetInstance.getMyValue()不存在

父Meteor模板是否可以直接访问子模板?理想情况下,我希望使用带有API的小部件模板。我希望有这样的事情:

mypage.html

<template name="myPage">
   <div class="widgetContainer"></div>
   <button>submit</button>
</template>
上述操作不起作用,因为
myWidgetInstance.getMyValue()
不存在。外部代码似乎无法访问实例上的模板帮助器函数


有没有人像我在上面尝试的那样使用Meteor模板?或者这更适合单独的jQuery小部件?如果是这样,那就太遗憾了,因为我仍然希望我的小部件模板能够从Meteor提供的功能中获益。

可以访问子模板帮助器功能。 您的示例将在应用少量修复后生效:

修正1:
getValue()
而不是
getMyValue()

修复3:
不应该有关闭标记

<template name="myWidget">
   <input type="text" value="sample value">
</template>


尝试将myWidget.js中的
Template.myWidget.getValue
重命名为
Template.myWidget.getMyValue
或尝试替换
var val=Template.data.myWidgetInstance.getMyValue()带有
var val=template.data.myWidgetInstance.getValue()太好了,谢谢!有没有一种方法可以在不使用UI.render()的情况下获取模板实例?也就是说,如果我在mypage.html中使用{{>messageEditor}}创建模板?
<template name="myWidget">
   <input></input>
</template>
Template.myWidget.getValue = function(){
    return this.$('input').val();
}
Template.myPage.events({
    'click button': function(e, template){
         // I don't want this logic to live inside of mywidget.js.
         // I also don't want this template to know about the <input> field directly.
         var val = template.myWidgetInstance.getValue();
         console.log(val);
    }
});
Template.myWidget.getValue = function(){
    return $('input').val();
}
<template name="myWidget">
   <input type="text" value="sample value">
</template>