简体   繁体   中英

How to change the value of a client-side variable from the Meteor shell?

In /lib/global.js I have:

footerButtons = ['x','y','z'];

I use this in a client-side Spacebars helper:

Template.footer.helpers({
  footerButtons: function(){
    return footerButtons;
  }
});

Then from the meteor shell I do:

footerButtons = ['a', 'b', 'c'];

After I ran this the client-side helper did not update.

Can a Meteor shell command change a client-side variable value?

Meteor shell interfaces directly with the server. While footerButtons is defined on both the client and the server, the Meteor shell command you execute will only affect the server value. Since there isn't reactivity built-in on a global variable like that, your footerButtons client value doesn't change. You'd have to use a Meteor.method or something to get the value from the server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM