1

我正在嘗試製作一個自定義窗體嚮導,該向導將包含基於特定條件的不同autoform步驟。下面連接了一個簡化的meteorPad例子。當被動數據源(會話變量)改變被動計算(模板幫助器)運行時,由控制檯輸出確認。但是,該模板未更新,仍具有相同的步驟數。有什麼我需要做的,使模板更新正確嗎?謝謝! http://meteorpad.com/pad/cPWShRiTKYpBaMahn/Leaderboard當模板幫助程序重新運行時,流星模板不會更新

HTML

<body> 
    {{> basicWizard}} 
    {{> changeSteps}} 
</body> 

<template name="basicWizard"> 
<!--shouldn't the steps variable update when the helper runs?--> 
    {{> wizard id="basic-wizard" steps=steps}} 
</template> 

<template name="changeSteps"> 
<button id="changeStepsButton"> change number of Steps </button> 
</template> 

客戶端代碼

Session.set('twoSteps', false); 

information = new SimpleSchema({ 
    password: { 
    type: String, 
    label: 'password', 
    }, 
}); 
confirm = new SimpleSchema({ 
    userName: { 
    type: String, 
    label: 'blah', 
    }, 
}); 

Template.basicWizard.helpers({ 
    steps: function() { 
     var ret = []; 
     if (Session.get("twoSteps")) { 
     ret[ret.length] = 
     { 
      id: 'information', 
      title: 'Information', 
      schema: information, 
     } 
     } 
     ret[ret.length] = 
     { 
      id: 'confirm', 
      title: 'Confirm', 
      schema: confirm , 
     } 
     console.log("num steps: " + ret.length) 
     return ret; 
    } 
    }); 

Template.changeSteps.events({ 
    "click #changeStepsButton": function (event) { 
    Session.set('twoSteps', !Session.get("twoSteps")); 
    }, 
}) 
+0

就我個人而言,meteorpad無法加載,它永遠處於加載狀態,在控制檯中我會看到400和404錯誤代碼。也許這是我本地設置(防火牆等)的問題,但是你可以在其他地方發佈你的代碼嗎? – Petr

+0

謝謝你讓我知道!我將代碼添加到問題中。 – jjr4826

回答

1

貌似麻煩的是,嚮導不處理步驟被動。我懷疑這是在精靈包下面的代碼:

「新WizardConstructor」的電話是我認爲的反應是打破: Template.wizard.created =函數(){VAR ID = this.data。 id || defaultId; this.wizard = wizardsById [id] = new WizardConstructor(this.data); };

某處在嚮導構造它這樣做呼叫: _.each(this.steps,功能(步驟){ self._initStep(步驟); });

但我不認爲Meteor知道在「this.data」更改時重新創建模板。從技術上講,巫術師並沒有對「步驟」的約束,這就是爲什麼它不起作用。我懷疑嚮導包的創建者不打算以這種方式使用它。