parse-platform - 在客户端在 LiveQuery 上接收之前修改对象
问题描述
我试图在我的云代码中隐藏一些字段,用于在 afterFind 触发器中将阻塞值设置为默认数字的类。
Parse.Cloud.afterFind("Question", async (req) => {
let objs = req.objects;
if (req.master) return req.objects;
objs.forEach(obj => {
obj.set("answer", -100);
});
return objs;
});
它工作正常,但是当我在更新事件中使用 LiveQuery 订阅这个类时,我可以在我的控制台中看到所有字段。
sub.on("update", async (obj) => {
console.log(obj.toJSON());
//this.getQuestion(this.cat_id);
});
有没有办法修改/阻止 LiveQuery 事件中的字段?
编辑:
我正在尝试实现 protectedFields 但它给出了相同的响应
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'id',
masterKey: process.env.MASTER_KEY || 'master', //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't forget to change to https if needed
liveQuery: {
classNames: ["Message", "Marker", "Question"] // List of classes to support for query subscriptions
},
protectedFields: {
Question: {
"*": ["answer", "active"]
}
} });
实时查询:
async subToQuestions(category) {
let questionQuery = new Parse.Query(Question);
questionQuery.equalTo("category", category);
try {
return await questionQuery.subscribe();
}
catch (e) {
throw e;
}
}
类别是一个指针
async subToQuestion(cat) {
let sub = await this.ParseService.subToQuestions(cat);
sub.on('create', async (obj) => {
console.log(obj.toJSON());
});
sub.on("update", async (obj) => {
console.log(obj.toJSON());
});
}
当我记录 LiveQuery 的结果时,它也会提示受保护的字段。
和 beforeFind for Question 类
Parse.Cloud.beforeFind("Question", async (req) => {
let query = req.query;
query.limit(1);
query.equalTo("active", true);
let now = new Date();
query.greaterThan("close_date", now);
query.include(["close_date", "text"]);
});
解决方案
推荐阅读
- c# - 在 UserControl 中处理来自主窗体的事件
- three.js - Three.js 在 OBJ(缓冲几何)的每个顶点(属性)上放置一个粒子
- c# - 如何验证rabbitmq是否安装在windows上?
- reactjs - 如何在 nextjs 中实现与服务器端渲染反应的错误边界?
- c# - System.Data.SqlClient.SqlException: 'Incorrect syntax near '2'.'
- google-apps-script - 使用应用程序脚本在谷歌表格中透视或转置数据
- python - 在 Python input() 函数中插入分隔符
- linux - 我想安装“邮件”但是
- drupal - Drupal 7. 如何在主内容字段中添加一段可重用的html(或块)
- python - Python:循环内矩阵每个元素的绝对值