2013-01-21 24 views
2

我有以下幾個非常簡單的流星應用:流星現場模板和純JS變量

在tags.html

<body> 
    {{> tags}} 
</body> 

<template name="tags"> 
    <input type="button" id="submit" value="Change tag" /> 
    {{tags}} 
</template> 

...在tags.js

var tags = 1; 

if (Meteor.isClient) { 
    Template.tags.tags = function() { 
     return tags; 
    }; 

    Template.tags.events({ 
     'click #submit': function() { 
      console.log("You pressed the button"); 
      tags += 1; 
     } 
    }); 
} 

當我開始就在旁邊的應用程序,我得到一個按鈕和VAR標籤(1)的初始值,這是正確的。 後來,當我點擊按鈕的標籤增加值(我可以在控制檯檢查),但模板不重新渲染。 這是正常的行爲嗎?我不知道我應該期待什麼 - 無法找到文檔中任何會告訴我的時候究竟現場模板被重新呈現。

如果我改變了var然而,使用Session對象:

在tags.html

<body> 
    {{> tags}} 
</body> 

<template name="tags"> 
    <input type="button" id="submit" value="Change tag" /> 
    {{tags}} 
</template> 

...在tags.js

var tags = Session.set("tags", 1); 

if (Meteor.isClient) { 
    Template.tags.tags = function() { 
     return Session.get("tags"); 
    }; 

    Template.tags.events({ 
     'click #submit': function() { 
      console.log("You pressed the button"); 
      Session.set("tags", Session.get("tags") + 1); 
     } 
    }); 
} 

...所有工作正常。

任何人都可以擺脫一些更多的光線?

回答

3

這是正常的。相關文件是here

反應的數據源,可以觸發的變化是:

  • Session變量
  • 數據庫查詢的集合
  • Meteor.status
  • Meteor.user
  • Meteor.userId
  • 流星.loggingIn
+0

非常感謝Sjoerd。期待在海牙流星聚會上與您見面:-) – babbata