Parse platform 如何遍历对象的所有字段
我有一个对象,大约有23列。有没有一种方法可以自动遍历每一列?而不是使用Parse platform 如何遍历对象的所有字段,parse-platform,Parse Platform,我有一个对象,大约有23列。有没有一种方法可以自动遍历每一列?而不是使用.get(“column\u NAME”)专门选择每一列 谢谢大家。也就是说a类a--带有字段id,创建数据,更新数据,a,b,c和obj是a的一个实例 obj.attributes是一个对象,它包含a、b、c和id,createdAt,updateAt是obj的属性 以下示例显示了web控制台中除特殊字段(id,createdAt,updatedAt)之外的所有字段的名称 Object.keys(obj.attribute
.get(“column\u NAME”)
专门选择每一列
谢谢大家。也就是说a
类a
--带有字段id
,创建数据,更新数据,a
,b
,c
和obj
是a
的一个实例
obj.attributes
是一个对象,它包含a
、b
、c
和id
,createdAt
,updateAt
是obj
的属性
以下示例显示了web控制台中除特殊字段(id
,createdAt
,updatedAt
)之外的所有字段的名称
Object.keys(obj.attributes).forEach(function(fieldName) {
console.log(fieldName);
});
更简单地说:
object.get('COLUMN\u NAME')
相当于object.attributes.COLUMN\u NAME
因此,如果您执行console.log(object.attributes)
操作,您将获得一个JS对象作为示例:
{
"cheatMode":true
"createdAt":Tue Oct 30 2018 10:57:08 GMT+0100 (heure normale d’Europe centrale) {} (this is a JS Date object)
"playerName":"Sean Plott"
"score":1337
"updatedAt":Tue Oct 30 2018 12:18:18 GMT+0100 (heure normale d’Europe centrale) {} (this is a JS Date object)
}
具有所有属性及其值。
就这些
ParseServer查询的完整示例代码
const GameScore = Parse.Object.extend("GameScore");
const mainQuery = new Parse.Query(GameScore);
mainQuery.equalTo("cheatMode", true);
mainQuery.find().then(async (response) => {
response.map(function(object){
console.log(object.attributes)
// Will log for example :
// {
// "cheatMode":true
// "createdAt":Tue Oct 30 2018 10:57:08 GMT+0100 (heure normale d’Europe centrale) {} (this is a JS Date object)
// "playerName":"Sean Plott"
// "score":1337
// "updatedAt":Tue Oct 30 2018 12:18:18 GMT+0100 (heure normale d’Europe centrale) {} (this is a JS Date object)
// }
})
});
parseObject.attributes
对不起。你能详细说明一下吗?