如何将 Parse.User 数据保存为数组指针
How do I save Parse.User data as pointer of arrays
嗨,我正在使用 Parse Javascript API。
我试图将用户对象保存为用户数组的指针。
但结果是
[{"__type":"Pointer","className":"_User","objectId":"a85SoYwEiE"}]
你能给我建议吗?
这是我的代码
if (mentions.length > 0) {
var query = new Parse.Query(Parse.User);
query.containedIn("username", mentions);
query.find().then(function(users) {
// each of results will only have the selected fields available.
var MensionNoti = Parse.Object.extend("Notification");
var mentionNoti = new MensionNoti();
//set by as CurrentUser
mentionNoti.set("notiBy", commentBy);
for (var i = 0; i < users.length; i++) {
// This does not require a network access.
//var user = users[i];
var userPointer = Parse.User.createWithoutData(users[i].id) ;
mentionNoti.addUnique("notiArray", userPointer);
}
//mentionNoti.set("notiArray", users);
mentionNoti.set("type", "mention");
//set Comment
mentionNoti.set("messageText", comments);
mentionNoti.set("checked", false);
mentionNoti.set("postObj", results);
mentionNoti.save();
});
}
试试这个。我没有测试代码,但从技术上讲,它应该可以工作。
var userArray = [];
for (var i = 0; i < users.length; i++) {
// This does not require a network access.
var userPointer = Parse.User.createWithoutData(users[i].id) ;
userArray[i] = userPointer;
}
mentionNoti.addUnique("notiArray", userArray);
...
mentionNoti.save();
希望这对您有所帮助:)
嗨,我正在使用 Parse Javascript API。
我试图将用户对象保存为用户数组的指针。
但结果是
[{"__type":"Pointer","className":"_User","objectId":"a85SoYwEiE"}]
你能给我建议吗?
这是我的代码
if (mentions.length > 0) {
var query = new Parse.Query(Parse.User);
query.containedIn("username", mentions);
query.find().then(function(users) {
// each of results will only have the selected fields available.
var MensionNoti = Parse.Object.extend("Notification");
var mentionNoti = new MensionNoti();
//set by as CurrentUser
mentionNoti.set("notiBy", commentBy);
for (var i = 0; i < users.length; i++) {
// This does not require a network access.
//var user = users[i];
var userPointer = Parse.User.createWithoutData(users[i].id) ;
mentionNoti.addUnique("notiArray", userPointer);
}
//mentionNoti.set("notiArray", users);
mentionNoti.set("type", "mention");
//set Comment
mentionNoti.set("messageText", comments);
mentionNoti.set("checked", false);
mentionNoti.set("postObj", results);
mentionNoti.save();
});
}
试试这个。我没有测试代码,但从技术上讲,它应该可以工作。
var userArray = [];
for (var i = 0; i < users.length; i++) {
// This does not require a network access.
var userPointer = Parse.User.createWithoutData(users[i].id) ;
userArray[i] = userPointer;
}
mentionNoti.addUnique("notiArray", userArray);
...
mentionNoti.save();
希望这对您有所帮助:)