0
我一直在努力解決這個問題幾天了,基本上我試圖完成的是添加一個自定義屬性到我加載的每個事件數據庫。 我在周圍搜索了一段時間,發現了其他函數中的addAttr函數。這個函數在添加和保存一個新事件時工作得很好,但顯然在我從數據庫加載的事件上使用它時不起作用。我試圖創建調度程序之前,並創建調度(通過使用getEvents,然後修改數據,並使用resetEvents更新它們),但沒有工作或者之後添加它..AlloyUI調度程序 - 從數據庫加載後添加自定義屬性
function Schedule(boundingbox, events)
{
var self = this;
this.schedule = null;
this.events = events || [];
this.boundingbox = boundingbox || "";
console.log(self.events);
YUI({ lang: 'nl-NL' }).use(
'aui-scheduler',
function (Y) {
var events = self.events;
var dayView = new Y.SchedulerDayView({ isoTime: true });
var weekView = new Y.SchedulerWeekView({ isoTime: true });
var monthView = new Y.SchedulerMonthView({ isoTime: true });
var eventRecorder = new Y.SchedulerEventRecorder({
on: {
save: function (event) {
var instant = this;
$.ajax({
type: "POST",
url: "/EventHandler",
data: { "content": this.getContentNode().val(), "startDate": new Date(this.get('startDate')).getTime()/1000, "endDate": new Date(this.get('endDate')).getTime()/1000 },
datatype: "json",
success: function (output) {
output = JSON.parse($.trim(output));
instant.addAttr("eventid", {
value: output.data.EV_ID,
setter: function(val) {
return output.data.EV_ID;
},
validator: function(val) {
return Y.Lang.isNumber(val);
}
});
}
});
},
edit: function (event) {
var instance = this;
console.log(instance.getAttrs()); // returns a list of attributes, eventid is not among them
console.log(instance.get("eventid")); // returns undefined
self.schedule.getEvents()[0].get("eventid") // returns undefined
},
delete: function(event) {
}
}
});
self.schedule = new Y.Scheduler({
strings: { agenda: 'Agenda', day: 'Dag', month: 'Maand', today: 'Vandaag', week: 'Week', year: 'Jaar', 'description-hint': "Een nieuwe afspraak" },
activeView: weekView,
boundingBox: self.boundingbox,
date: new Date(),
eventRecorder: eventRecorder,
firstDayOfWeek: 1,
items: self.events,
render: true,
views: [dayView, weekView, monthView]
});
$.each(self.schedule.getEvents(), function(key, value) {
value.addAttr("eventid", {
value: 123,
setter: function(val) {
return 123;
},
validator: function(val) {
return Y.Lang.isNumber(val);
}
});
});
console.log(self.schedule.getEvents()); // returns an array of events
console.log(self.schedule.getEvents()[0].get("eventid")); // returns the eventid: 123
}
);
}
正如你所看到的我一直在嘗試調試這些值以查看它是否有效,並且出於某種原因,當我在更新它們之後立即記錄事件ID時,它將返回正確的eventid,但是當我在on-edit中執行時,它返回undefined。
有人知道我在做什麼錯嗎?