簡體   English   中英

流星:僅在客戶端修改集合

[英]Meteor: Modify collection on client side only

我在客戶端訂閱了一個服務器端集合。 客戶端無權訪問服務器端集合。

我只想在客戶端上修改集合,並在我停止訂閱/移動到另一條路線時銷毀該更改。

有可能嗎?

謝謝您的回答。

我會在客戶端上使用轉換,如下所示:

var Books = new Meteor.Collection('books', {
    transform: function(doc){

        /*
            A doc looks like this:
            {
                _id: "...",
                title: "A nice title..."
            }
        */

        doc.clientTitle = new ReactiveVar("")

        doc.setClientTitle = function(title){
            this.clientTitle.set(title)
        }

        doc.getTitle = function(){
            var clientTitle = this.clientTitle.get()
            if(clientTitle == ""){
                return this.title
            }else{
                return clientTitle
            }
        }

    }
})

然后使用theBook.getTitle()獲取標題,並使用theBook.setTitle('The new title')僅在客戶端上對其進行更新。

注意: ReactiveVar來自軟件包reactive-var

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM