lit*_*ito 10 javascript arrays parse-platform
不是要求Parse.com问题的最佳时刻,但我必须继续使用解析器几个月.这是我的问题:
在Parse.com中我使用的是Javascript SDK.我有一个类User的指针数组:
[{userObject1.id}, {userObject2.id}, {userObject3.id}]
当我只有要删除的对象的id时,如何从数组内部删除对象{userObject2} ?
目前我正在通过使用array.splice(indexDelete,1); 执行forEach循环来删除内部对象.我正在寻找更好的解决方案.
var wasSomethingDeleted = 0;
var MyParseFollow = Parse.Object.extend('Follow');
var query = new Parse.Query(MyParseFollow);
query.equalTo("user", channelUser); // fetch all followers
query.first().then(
function (Follow) {
if (Follow){
if (Follow.get("followedBy").length > 0){ // check if there is any follower
var listOfFollowers = Follow.get("followedBy"); // get the array of userObjects of followers
var indexDelete = 0;
listOfFollowers.forEach(function(user){
if( user.id == Parse.User.current().id ){ // I want to remove the current authenticated user
wasSomethingDeleted++;
listOfFollowers.splice(indexDelete, 1); // remove the element
}else{
indexDelete++;
}
});
if( wasSomethingDeleted > 0 ){
Follow.set('followedBy', listOfFollowers); // save new updated array list of followers
Follow.save();
}
}
}
}
);
Run Code Online (Sandbox Code Playgroud)
vit*_*ore -1
我相信这应该有效
var User = Parse.Object.extend("User");
var user = new User();
user.id = "UserID1";
user.destroy().then(console.log.bind(console))
Run Code Online (Sandbox Code Playgroud)
或者
var user = User.createWithoutData("UserID1");
user.destroy().then(console.log.bind(console))
Run Code Online (Sandbox Code Playgroud)
由于您有多个用户 ID,您可能需要使用Parse.Object.destroyAll
方法
归档时间: |
|
查看次数: |
589 次 |
最近记录: |