简体   繁体   中英

Use list.js in Meteor with data published from the server to the client

I'm currently working on a meteor-Application where I want to use the list.js-JavaScript Library with Meteor.

The use-Case is that I have some data in my MongoDB on the server which I publish to the client. This data should now be rendered in a list and list.js should make it searchable.

The data is published to the client (after a short delay I get the data in the view). But it seems that the list.js-Library is run before the data hits the client. The console says that the array which is searchable only consists of "undefined".

What I've tried now is to use Template.rendered where I put my code of list.js in. But Template.rendered gets fired when the template is rendered, not when the data is receiving the client. It seems that the data arrives too late to be grabbed by list.js.

Is there something I can do so that list.js will start when the data successfully arrived at the client? Is there something like Data.received?

Thanks in advance!

Unfortunately, that is not the meteor-way to do it. Once you get it working you will see that it lacks performance and proper reactivity.

You should instead look into using meteor's excellent reactivity and do it using template helpers, that way it will be reactive and you can scale it without performance issues.

I found a good answer to your question in the Unofficial Meteor FAQ That describes how to know when your subscription is ready (reactive data).

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