我有一个模板帮助器,用于显示具有反应性var schoolFindQuery的学校
Template.schoolCompareCenterList.helpers({
schools(){
console.log("schoolFindQuery is :" + schoolFindQuery);
let school = Schools.find(JSON.parse(schoolFindQuery), {limit : 20});
console.log("school count is : " + school.count());
return school;
}
})
和schoolFindQuery响应变量随按钮点击而变化,按钮点击订阅续订,ui也相应更改。奇怪的是,当订阅返回数据没有问题,但每当订阅返回任何数据,之后Helper代码将不会重新运行订阅更改(即使我可以看到与流星玩具的订阅)和ui没有显示任何数据。 我的订阅代码如下,
this.autorun(function() {
if(subscription)
subscription.stop()
//This reactive variables set by buttons and by the ghelp of reactivty subscription rerun
query = "{"
if(_sTy__.get() != 0 && _sTy__ != null)
query += "\"schoolType.schoolT\" : \"" + _sTy__.get()+ "\","
if (_sTy2__.get() != 0 && _sTy2__ != null)
query += "\"schoolType.schoolTT\" : \""+ _sTy2__.get() +"\","
if(regexSchoolName.get() != 0 && regexSchoolName.get() != null )
query += "\"schoolName\" : {\"$regex\": \".*" + regexSchoolName.get() + ".*\", \"$options\": \"i\"},"
query += "\"haveSchoolDetailInfo\" : true}"
subscription = Meteor.subscribe("schoolCompare.infinite.publish", query, 20, 0);
schoolFindQuery = query;})
提前致谢。
答案 0 :(得分:0)
我建议你看一下本教程,它解释了会话变量,Reactive Dict和Reactive Var:https://blog.meteor.com/the-meteor-chef-reactive-dict-reactive-vars-and-session-variables-971584515a27#.undr5c1f0