2013-04-03 26 views
-1

謝謝大家,我已經使用Akshat的解決方案迭代解決了問題, 並且特別感謝Akshat,除了這個問題之外,我已經幫助我解決了另一個問題 - 快速,準確和真棒問題解決!如何隱藏在Meteor中加載頁面後添加的所有文檔?

好的,所以我試圖在流星中創建一個後期系統,我希望流星不顯示新帖子,只計算它們並讓用戶決定何時顯示它們。在此先感謝Daniel。

(如Twitter的X新推文)

編輯: 大家好,感謝到目前爲止所有的答案的。事情是,這可能是一個非常具體的情況,因爲我也實現無限滾動,因此使其無反應將無濟於事。

代碼:

var Posts = new Meteor.Collection("posts"); 
if (Meteor.isClient) { 
    Session.set("current_page",1); 
Template.posts.posts= function() { 
     return Posts.find({}, {limit: Session.get("current_page")*20,sort: {created_at:-1}}); 
    }; 

function getDocHeight() { 
    var D = document; 
    return Math.max(
     Math.max(D.body.scrollHeight, D.documentElement.scrollHeight), 
     Math.max(D.body.offsetHeight, D.documentElement.offsetHeight), 
     Math.max(D.body.clientHeight, D.documentElement.clientHeight) 
    ); 
} 
$(window).scroll(function() { 
    if($(window).scrollTop() + $(window).height() > getDocHeight() - 100) { 
     Session.set("current_page",Session.get("current_page")+1); 
    } 
}); 
} 
+0

請附上您已張貼問題時試了一下代碼示例。 – 2013-04-03 20:12:28

+0

將代碼添加到您的問題中,而不是在評論中。您可以隨時「編輯」您的問題以添加更多信息。您還可以在問題中添加格式,以便閱讀。感謝您發佈您的代碼。 – 2013-04-03 20:44:28

回答

1

可以使用塊助手#constant標記的區域恆定。它將在第一次創建模板時加載,然後纔會加載。

See the Meteor docs

實施例:page.js

Template.page.collection = function() { 
    return MyCollection.find({}); 
} 

例:page.html中

<template name="page"> 
    {{#consant}} 
     {{#each collection}} 
       {{this}} 
     {{/each}} 
    {{/constant}} 
</template> 
+0

很好的答案,雖然不知道我可以說我的好多了,但這也可以派上用場,使其中的一部分不變,比如想保持被動計數的位數 – Akshat 2013-04-03 20:24:15

1

很多好的答案!另一種方法是對您的帖子使用非反應性查詢,您希望它以這種方式行事。新的結果基本的reactivity,可以disable reactivity結果在查詢

e.g

MyCollection.find({}, {reactive:false}); 
+0

+1比我的回答好得多 – Swadq 2013-04-03 20:18:20