我们可以使用equalTo
在解析平台中设置数据库中的数据(找不到数据)吗?
它不在文档上
答案 0 :(得分:0)
不。 equalTo()
函数仅存在于Parse.Query实例中,用于搜索数据。为了设置数据,您需要使用Parse.Object实例中存在的set()
函数。就像下面的代码一样:
const GameScore = Parse.Object.extend('GameScore');
const query = new Parse.Query(GameScore);
const gameScore = await query.get('xWMyZ4YEGZ');
gameScore.set('score', 1337);
gameScore.set('playerName', 'Sean Plott');
gameScore.set('cheatMode', false);
gameScore.set('skills', ['pwnage', 'flying']);
await gameScore.save();
const GameScore = Parse.Object.extend('GameScore');
const query = new Parse.Query(GameScore);
query.equalTo('skills', 'flying');
const gameScores = await query.find();
gameScores.forEach(gameScore => {
gameScore.set('score', 1337);
gameScore.set('playerName', 'Sean Plott');
gameScore.set('cheatMode', false);
gameScore.set('skills', ['pwnage', 'flying']);
});
await Parse.Object.saveAll(gameScores);
您可以找到有关如何查找和保存对象here
的更多信息。答案 1 :(得分:0)
使用代码示例,您还可以像这样保存: (https://parseplatform.org/Parse-SDK-JS/api/master/Parse.Object.html#save)
const GameScore = Parse.Object.extend('GameScore');
const query = new Parse.Query(GameScore);
const gameScore = await query.get('xWMyZ4YEGZ');
await gameScore.save({
score: 1337,
playerName: 'Sean Plott',
cheatMode: false,
skills: ['pwnage', 'flying'],
});