Is there a way to pass variables into templates in Meteor?

前端 未结 9 2113
深忆病人
深忆病人 2020-12-01 01:37

I\'ve been experimenting with Meteor and ran into something I couldn\'t figure out. For fun, I was trying to make a slot machine. I had the following HTML:

&         


        
9条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-01 02:18

    This is what I have done to achieve it. I am fairly new to Meteor so there may be a better way:

    Slot.html:

    
      Slot
    
    
    
      
    {{> slots}}

    Slot.js:

    if (Meteor.is_client) {
      Template.slots.slots = function () {
        var returnArray = new Array();
        returnArray[0] = { 'number': 10 };
        returnArray[1] = { 'number': 87 };
        returnArray[2] = { 'number': 41 };
        return returnArray;
      };
    }
    
    if (Meteor.is_server) {
      Meteor.startup(function () {
        // code to run on server at startup
      });
    }
    

    Hope this was some help to you!

提交回复
热议问题