how would you build pinterest like page with meteor.js

跟風遠走 提交于 2019-12-03 07:45:19

I finally solved this problem. The solution is to have client only Collection, like that:

# on client
# client side only collection
ProductsDisplayed = new Meteor.Collection(null)

then when scrolling point is reached ask server for next N (limitNo) products

# on client
Meteor.call 'getProducts', limitNo, skipNo, (err, products) =>

  _.each products, (item, index) =>
    # get rid of _id
    delete item._id

    ProductsDisplayed.insert( item )

skipNo is incremented by N, to always ask for next set of data. And on server side I have:

# on server
Meteor.methods
  getProducts: (limitNo, skipNo) ->

    productsCursor = Products.find( {}, {
      limit: limitNo,
      skip: skipNo
    })

    productsCursor.fetch()

this Meteor method returns me next set of products from Products collection.

Of course view template displays ProductsDisplayed collection content:

Template.products.products = ->
  ProductsDisplayed.find {}

So, what do you think?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!