【发布时间】:2018-05-24 20:53:16
【问题描述】:
我想收集从模板中收集的变量(用户 _id),并使用会话将其传递给另一个模板。然后我想显示这个变量。 实际上它似乎在变量的集合和传递给另一个模板中工作,但我无法在第二个模板中显示用户的信息......
这是我的代码:
HTML
<template name="main"><!--Template 1-->
<table>
<tr>
<th>Patient</th>
</tr>
{{#each allUsers}}
<tr>
<th><label><input type="radio" class="selected" name="patient" value="{{this._id}}"><i class="fa fa-user"></i> {{this.profile.lastName}} {{this.profile.firstName}}</label></th>
</tr>
{{/each}}
</table>
{{>test}}
</template>
<template name="test"> <!--Template 2-->
<p>Name is <button class="test" name="patient" value="{{this._id}}">Test</button></p>
<div name="show">Name: {{this.profile.firstName}}</div>
</template>
JS
Template.main.events({
'click .selected': function (){
var selPat = $('input[name="patient"]:checked').val();
Session.set("selPat",selPat);
console.log("collect", selPat);
}
});
Template.test.events({
'click .test': function(){
var PAT= Meteor.users.findOne({ _id: Session.get("selPat")});
console.log("pass", PAT);
return PAT;
}
});
Template.patients.helpers({
allUsers: function() {
return Meteor.users.find({});
}
});
我想在模板 2 中显示在模板 1 中使用 {{this.profile.firstName}} 选择的用户的名字
【问题讨论】:
-
Template.test.events你在这里混合了事件和助手功能。return PAT应该在帮助程序中,而不是在事件本身中。
标签: javascript html templates meteor