mantra-sample-blog-app icon indicating copy to clipboard operation
mantra-sample-blog-app copied to clipboard

How to send params to container from component ?

Open lyquocnam opened this issue 8 years ago • 12 comments

we have save query like: {_id: id}, {limit: 10} ... how to send them to container query from server side?

lyquocnam avatar Feb 19 '16 16:02 lyquocnam

Could you add more information to this?

arunoda avatar Feb 19 '16 23:02 arunoda

we have container:

function composer(props, onData) {
  const handle = Meteor.subscribe('categories');
  if(handle.ready()) {
    const categories = Categories.find({}, {sort: {_id: 1}}).fetch();
    onData(null, {categories});
  };
};

how to find: const categories = Categories.find({_id: id}, {limit: limit, skip: skip}).fetch();

more: this good featured from laravel: it can return pagination object from server:

{
   data: {...},
   current_page: 1,
   last_page: 5,
   ...
}

in Meteor, can we do this ? thanks so much !

lyquocnam avatar Feb 20 '16 02:02 lyquocnam

@lyquocnam Are you talking about this: http://docs.meteor.com/#/basic/Mongo-Collection-find

xcv58 avatar Feb 20 '16 03:02 xcv58

yeah but my problem is how to send params to it from component. this query in container. and how to server can send pagination object to client, this will be simpler many times i guess, thanks @xcv58 nice to meet u !

lyquocnam avatar Feb 20 '16 04:02 lyquocnam

@lyquocnam why not use LocalState to store the mongo selectors?

kokjinsam avatar Feb 20 '16 04:02 kokjinsam

@sammkj i'm new so i dont' know about that... not any tuts from this ? @@ thanks @sammkj

lyquocnam avatar Feb 20 '16 04:02 lyquocnam

@lyquocnam uhm. I'm in the process of learning as well. haha.

I use URL params to do filtering. For example, www.example.com/categories?type=shoe&stars=5. Then I use FlowRouter's API to retrieve the value.

Or you can set / update the LocalState / Session when user changes the filters. Perhaps this article might help you.

kokjinsam avatar Feb 20 '16 05:02 kokjinsam

i used URL params. this work ! any solution about get pagination object from server like laravel ?

{
   data: {...},
   current_page: 1,
   last_page: 5,
   ...
}

thanks @sammkj !

lyquocnam avatar Feb 20 '16 05:02 lyquocnam

@lyquocnam I don't have any experience with Laravel. For pagination, you will need to count all the documents and do all the pagination stuffs by yourself or you can use meteor packages like this one

kokjinsam avatar Feb 20 '16 05:02 kokjinsam

Ya, i can custom a pagination use for react by publishCount from server. but i try to find better solutions for this and laravel resolved this good. i trying to do like that. thanks @sammkj , you are the best :+1:

lyquocnam avatar Feb 20 '16 05:02 lyquocnam

When talking about vanilla Mantra with ReactiveDict as LocalState, answer on your question will be to create Action which set it. Than you can call that action from your Component to set value in the application logic. And when you use that value inside container to filter data it will work as you want.

ShockiTV avatar Feb 20 '16 10:02 ShockiTV

thanks @ShockiTV i'll try :dancers:

lyquocnam avatar Feb 20 '16 11:02 lyquocnam