gpt4 book ai didi

Meteor:对客户端隐藏属性

转载 作者:行者123 更新时间:2023-12-04 01:44:52 26 4
gpt4 key购买 nike

有没有办法从客户端更新中排除某些属性?

在控制台中检查集合时应该看不到该属性

最佳答案

绝对地。

  • 删除 autopublish默认开启的包:meteor remove autopublish
  • 创建您的收藏:Rooms = new Meteor.Collection("rooms");不需要条件 isServer 或 isClient,因为这应该同时存在于
  • 在您的服务器端代码中,publish通过将您不希望客户端拥有的字段清零,只保留您集合的一个子集:
    if (Meteor.isServer) {
    //you could also Rooms.find({ subsetId: 'some_id' }) a subset of Rooms
    Meteor.publish("rooms", function () {
    return Rooms.find({}, {fields: {secretInfo: 0}});
    });
    }

    注意:设置 {secretInfo: 0}以上没有设置secretInfo的所有实例对于 Rooms 中的每一行收藏归零。它删除 该字段完全来自客户端集合。想想0作为关闭开关:)
  • 将客户端订阅到已发布的集合:
    if (Meteor.isClient) {
    Deps.autorun(function() {
    Meteor.subscribe("rooms");
    });
    }

  • 希望这可以帮助!

    关于Meteor:对客户端隐藏属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13923933/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com