5
votes

I am new to meteor and have been trying to pass a value from an arraylist to a href pathfor element.

I have a template

<template name="Listing">
  {{#each data}}
    <a href="{{pathFor 'listingbycompanyL1' this}}">{{this}}</a><br/>
  {{/each}}
  <a href="javascript:history.back()">Back</a>
</template>

The data being sent into the template using a helper is basically an array of Strings from the following helper

'data': function(){
  var distinctOrgListing = _.uniq(MyCustomCollection.find({}, {sort: {orgName: 1}, fields: {orgName: true}}).fetch().map(function(x) {return x.orgName;}), true);
  console.log("Listing.helpers : distinct listings :"  +distinctOrgListing)
  return distinctOrgListing;
}

which will return me some data in form of a list of strings. For Example when printed to console i will get

Listing.helpers : distinct listings : a,b,c

I want to

  1. Send the value that i received to Iron Router as a param so that i can use the value do a collection search

My Router configuration for this is as follows :

this.route("listingbycompanyL1",{
  path:"/listingL1",
  layoutTemplate: 'ListingbycompanyL1',
  data: function(){
    var update=MyCustomCollection.find({orgName:"XXXX" }).fetch();
    return {
      update:update
    };
  }
});

How can i pass the values that i recieved (a,b,c) to IR and use it to do a search, where XXXX is a or b or c

1
It's not clear what you're trying to do in the router. The comment in your router code indicates that you're trying to avoid using a query parameter. At the same time your router is trying to find orgname: "XXXX" which has nothing to do with a,b,c. Is a,b,c always a triple or can be a tuple or a quadruple or any number? Have you thought about just setting a session variable (or reactive variable) in your template helper and referring to it from your route.Michel Floyd
Thanks for the comment. Basically I am creating hrefs using #each in the template successfully. I now want to pass value of the href to IR so that i can use this value to query my collection. PS: The comment in the IR is misleading, removed it.Madhup Narain

1 Answers

0
votes

Here's a simple parameterized route:

this.route("listingbycompanyL1",{
  // specify the strategy _id as an URL component instead of query parameter
  path:"/listingL1/:a",
  layoutTemplate: 'ListingbycompanyL1',
  data: function(){
    var update=MyCustomCollection.find({orgName: this.params.a }).fetch();
    return {
      update:update
    };
  }
});