简体   繁体   中英

Meteor filter collections depending on templates selected

I have 2 templates which both include a third template. The third template displays a collection of orders in a table. Based on which of the other 2 templates selected in the navigation the third template should display buy orders or sell orders

This passes a collection of orders to our third template which displays all of the orders

Template.ordersTable.helpers({
    orders : function () {
        return OrderList.find().fetch();
    }
});

Is there a meteor way of doing this that doesn't require duplicating templates and event handlers.

Thanks

There's a better way to do this than what jorjordandan suggested.

Template.ordersTable.helpers({
    orders: function () {
      var parentViewName = Template.instance().view.parentView.name;

      if (parentViewName === 'Template.someTemplate') {
        // do something
      } else if (parentViewName === 'Template.anotherTemplate') {
        // do something else
      }
    }
});

You could use a session variable flag to toggle the third template's data in a helper.

For instance:

getData: function(){
  if (Session.get("isBuyTemplate")=== true){
     //get buy data
  } else {
     // get sell data
  }
}

And then toggle the Session variable in an event helper where you are changing the Template selection.

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