简体   繁体   English

将Meteor中的list.js与从服务器发布到客户端的数据一起使用

[英]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. 我目前正在开发一个流星应用程序,我想将list.js-JavaScript库与流星一起使用。

The use-Case is that I have some data in my MongoDB on the server which I publish to the client. 用例是我在发布到客户端的服务器上的MongoDB中有一些数据。 This data should now be rendered in a list and list.js should make it searchable. 现在应将此数据呈现在列表中,并且list.js应该使其可搜索。

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. 但是似乎list.js-Library是在数据到达客户端之前运行的。 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. 我现在尝试的是在将list.js代码放入其中的地方使用Template.rendered。但是在渲染模板时(而不是在数据接收客户端时)会触发Template.rendered。 It seems that the data arrives too late to be grabbed by list.js. 看来数据到来太迟,无法被list.js捕获。

Is there something I can do so that list.js will start when the data successfully arrived at the client? 我有什么办法可以使list.js在数据成功到达客户端时启动? Is there something like Data.received? 是否有类似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). 我在非官方流星常见问题解答中找到了一个很好的答案,该问题描述了如何知道订阅准备就绪的时间(活动数据)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM