我想知道是否有人可以帮我解决我与Parse有关的问题。
我使用javascript(angular和bootstrap3)来构建一个小应用程序。
我现在遇到了一个问题,我正在尝试向现有的Events
对象添加日期数组并将新日期保存到Parse后端,但无论我尝试什么,我似乎总是有当我查看对象浏览器时undefined
。
console.log("setSuggestedDate");
console.log(conEvent.selectedEvent.newDate);
//get existing dates
//convert this date to JS date Sring
//check if new date is in existing dates
//add new date to existing dates or +1 the count of the existing new date
//update the object server-side
//trigger new getEvents()
var dates = conEvent.selectedEvent.dates;
console.log(dates);
var nDate = new Date(conEvent.selectedEvent.newDate);
var date = nDate.valueOf().toString();
console.log(date);
if(dates){
if(dates[date]){
dates[date].count++;
}else{
dates[date] = {
"count": 1,
"suggestedBy": Parse.User.current()
}
}
}else{ //No Dates
dates = {}
dates[date] = {
"count": 1,
"suggestedBy": Parse.User.current()
}
}
console.log(dates);
var eEvent = Parse.Object.extend("Event");
var query = new Parse.Query(eEvent);
console.log(conEvent.selectedEvent.id);
query.get(conEvent.selectedEvent.id, {
success: function(e) {
console.log("success");
eEvent.set("dates", dates);
eEvent.save();
},
error: function(object, error) {
// The object was not retrieved successfully.
// error is a Parse.Error with an error code and message.
}
});
我已经确定所有变量都能正常工作,当我到达var eEvent = ....
时,日期是一个新的日期对象(代码中的第一个else语句)
我尝试过按照指南here
但没有成功。
如果有人能在代码中看到我的错误,请帮助我,谢谢
conEvent.selectedEvent的一个示例(从控制台复制):
$$hashKey: "object:6"
creator: ParseUser
dates: undefined
description: "just a test"
id: "F0QEbvwqLK"
name: "test"
newDate: Wed Dec 30 2015 00:00:00 GMT+0000 (GMT Standard Time)
__proto__: Object