如何使用 javascript 从解析平台检索具有键和值的 for 循环中的行
How to retrieve rows in a for loop which has a key and value from parse-platform with javascript
我已经在使用 parse-platform 开发 java,我也想使用 javascript。我想给一个列和一个键并用 for 循环检索所有行。例如,在下面的代码中,我得到在项目列中具有 "key" 值的行,然后我想在 for 循环中使用它们。我如何使用 javascript.
做到这一点
我搜索了参考资料,找到了如何检索数据,但代码只占用了 1 行。我没有找到任何有关如何获取多行的信息
ParseQuery < ParseObject > query = ParseQuery.getQuery("query");
query.whereEqualTo("item", "key");
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List < ParseObject > objects, ParseException e) {
if (e != null) {
//for some errors
} else {
if (objects.size() > 0) {
for (ParseObject object : objects) {
//get datas which you want
object.getInt("key");
}
}
}
}
});
这段代码实际上是我的 java 代码,我想在 JS 中做几乎相同的事情,但我在 for 循环中遇到了麻烦。我找不到如何使用 Parseobjects 在 JS 中进行循环。
query = new Parse.Query("query");
query.equalTo("shift", "night");
query.first().then(function (person) {
if (person) {
console.log('object found successful with shift: ' + object.get("shift") + ' and id: ' + object.get("id"));
} else {
console.log("Nothing found, please try again");
}
}).catch(function (error) {
console.log("Error: " + error.code + " " + error.message);
});
我试过这段代码来检索所有晚上工作的人并写下它的 id。但问题是这段代码只能检索一个人。在文档中它写道它将 return 只有一个人,但我希望所有人 whp 都在晚上工作。
试试这个:
const query = new Parse.Query("query");
query.equalTo("shift", "night");
query.find().then(function (persons) {
if (persons.length > 0) {
persons.forEach(function (person) {
console.log('object found successful with shift: ' + person.get("shift") + ' and id: ' + person.id);
});
} else {
console.log("Nothing found, please try again");
}
}).catch(function (error) {
console.log("Error: " + error.code + " " + error.message);
});
我已经在使用 parse-platform 开发 java,我也想使用 javascript。我想给一个列和一个键并用 for 循环检索所有行。例如,在下面的代码中,我得到在项目列中具有 "key" 值的行,然后我想在 for 循环中使用它们。我如何使用 javascript.
做到这一点我搜索了参考资料,找到了如何检索数据,但代码只占用了 1 行。我没有找到任何有关如何获取多行的信息
ParseQuery < ParseObject > query = ParseQuery.getQuery("query");
query.whereEqualTo("item", "key");
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List < ParseObject > objects, ParseException e) {
if (e != null) {
//for some errors
} else {
if (objects.size() > 0) {
for (ParseObject object : objects) {
//get datas which you want
object.getInt("key");
}
}
}
}
});
这段代码实际上是我的 java 代码,我想在 JS 中做几乎相同的事情,但我在 for 循环中遇到了麻烦。我找不到如何使用 Parseobjects 在 JS 中进行循环。
query = new Parse.Query("query");
query.equalTo("shift", "night");
query.first().then(function (person) {
if (person) {
console.log('object found successful with shift: ' + object.get("shift") + ' and id: ' + object.get("id"));
} else {
console.log("Nothing found, please try again");
}
}).catch(function (error) {
console.log("Error: " + error.code + " " + error.message);
});
我试过这段代码来检索所有晚上工作的人并写下它的 id。但问题是这段代码只能检索一个人。在文档中它写道它将 return 只有一个人,但我希望所有人 whp 都在晚上工作。
试试这个:
const query = new Parse.Query("query");
query.equalTo("shift", "night");
query.find().then(function (persons) {
if (persons.length > 0) {
persons.forEach(function (person) {
console.log('object found successful with shift: ' + person.get("shift") + ' and id: ' + person.id);
});
} else {
console.log("Nothing found, please try again");
}
}).catch(function (error) {
console.log("Error: " + error.code + " " + error.message);
});