ios - 创建用于删除最后一天记录的后台作业
<p><p>如何从表格中删除最后一天的记录</p>
<pre><code>Parse.Cloud.job("deleteOldEntries", function(request, status) {
var GameScore = Parse.Object.extend("GameScore");
var query = new Parse.Query(GameScore);
var day = new Date();
day.setDate(day.getDate()-1);
query.lessThan("createdAt", day);
query.find({
success:function(results) {
console.log(results);
for (var i = 0, len = results.length; i < len; i++) {
var result = results;
result.destroy({});
console.log("Destroy: "+result);
}
status.success("Delete successfully.");
},
error: function(error) {
status.error("Uh oh, something went wrong.");
console.log("Failed!");
}
})
});
</code></pre>
<p>我正在使用此代码删除最后一天的记录,它已成功部署到服务器。之后我成功安排了作业,但记录不删除。</p>
<p>任何帮助表示赞赏。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><pre><code>Parse.Cloud.job("deleteMessages", function(request, status) {
Parse.Cloud.useMasterKey();
var ts = Math.round(new Date().getTime() / 1000);
var tsYesterday = ts - (24 * 3600);
var dateYesterday = new Date(tsYesterday*1000);
var query = new Parse.Query("Your Object Class");
query.lessThan("createdAt", dateYesterday);
query.find({
success: function(result) {
for(var i=0; i<result.length; i++) {
result.destroy({
success: function(object) {
status.success("Delete job completed");
alert('Delete Successful');
},
error: function(object, error) {
status.error("Delete error :" + error);
alert('Delete failed');
}
});
}
status.success("Delete job completed");
},
error: function(error) {
status.error("Error in delete query error: " + error);
alert('Error in delete query');
}
});
});
</code></pre></p>
<p style="font-size: 20px;">关于ios - 创建用于删除最后一天记录的后台作业,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/27313958/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/27313958/
</a>
</p>
页:
[1]