我有用於示出學校用反應性變種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不顯示任何數據。 我的訂閱代碼如下,提前
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;})
感謝。
確定schoolFindQuery是反應?它看起來像一個正常的變種;它應該設置不同。你能展示它的定義嗎? – zim
我將它定義爲var schoolFindQuery = new ReactiveVar();它直到空訂閱時才起作用 – ofcelik
您不通過賦值來改變一個被動變量,而是使用get()和set(newVal)方法。 – MasterAM