위의 해결 방법은 나에게 하나의 방법을 보여줬지만, 여전히 observe()와 연결되지 않은 클라이언트 데이터를 게시해야한다면 어떻게해야합니까? 아니면 어떤 컬렉션?
제 경우에는 제품이 1000 개입니다. 방문객을 끌어 들이기 위해 난수를 곱한 타임 스탬프를 업데이트하고 타임 스탬프별로 컬렉션을 표시하여 컬렉션을 "새로 고침"했습니다. 이 방문자에게 뭔가 일이 일어나고 있다는 인상을 주셔서 감사합니다.
내 refresh
메서드는 제품 수 (임의 수)를 반환합니다. 그 번호를 모든 고객에게 전달해야합니다. 나는 그것을했지만 추악한 해결 방법을 사용했다.
내 refresh
방법 세트 Session.set('lastRandomNo', random)
. BTW : Session이 서버 측에서 작동하는지 몰랐습니다. refresh
업데이트 제품 컬렉션.
그리고 위의 대답에 accoriding :
Meteor.publish 'refreshedProducts', ->
self = this
uuid = Meteor.uuid()
# create a new collection to pass ProductsMeta data
self.set('products_meta', uuid, { refreshedNo: 0 })
handle = Products.find().observe
changed: (newDocument, atIndex, oldDocument) ->
self.set('products_meta', uuid, { refreshedNo: Session.get('lastRandomNo') })
self.flush()
self.complete()
self.flush()
self.onStop ->
handle.stop()
및 클라이언트 측
가 :
ProductsMeta = new Meteor.Collection('products_meta')
# subscribe to server 'products_meta' collection that is generated by server
Meteor.subscribe('refreshedProducts')
ProductsMeta.find({}).observe
changed: (newDocument, atIndex, oldDocument) ->
# I have access to refreshedNo by
console.log ProductsMeta.findOne().refreshedNo
당신은 어떻게 생각하세요?
여기에 자세한 답변이 포함 된 최신 게시물이 있습니다. http://stackoverflow.com/questions/18584757/ –