如何在MeteorJS中制作动态值

时间:2017-08-15 18:44:16

标签: meteor meteor-blaze

我需要在meteor JS中设置一个变量或数组,无论何时发生变化。无论在页面上使用何处都会发生变化。

到目前为止,我已尝试在会话中设置值。

let in  = Session.get("in");

并在HTML中。以下工作正常。只要检测到数组中的更改

,它就会更改
   {{#each in}}
        <span class="selectable-tags"> {{this}} </span>
     {{/each}}

但每当我尝试使用以下内容将这些标签添加到其他div时。然后添加到其他div的那些不会改变。

 "click .selectable-tags"(e, t) {
  // sets the tags inside the Method  box on click 
    var el = e.target.cloneNode(true);
        el.setAttribute('contenteditable', false);
        document.querySelector('[contenteditable]').appendChild(el); },

使用流星与火焰UI。这可以用作参考link

编辑:提供Session.get或set以供参考。这是为了告诉这些值正在改变,因为它们在任何设置的任何事件中都会触发。

1 个答案:

答案 0 :(得分:0)

您需要添加一个帮助程序,它返回会话变量并在您的html代码中显示帮助程序:

 Template.yourtemplate.helpers({
   inHelper: ()=> {
     return Session.get('in');
   }    
 )}

在html中:

<div>{{inHelper}}</div>

inSession.set('in', newValue)的每次修改都会改变您的HTML。