gpt4 book ai didi

javascript - AlloyUI Scheduler - 从数据库加载后添加自定义属性

转载 作者:行者123 更新时间:2023-11-28 04:47:44 25 4
gpt4 key购买 nike

我已经为这个问题苦苦挣扎了几天,基本上我想要完成的是为从数据库加载的每个事件添加一个自定义属性。我搜索了很长一段时间,在其他函数中发现了 addAttr 函数。在添加和保存新事件时,此函数工作得非常好,但显然,在我从数据库加载的事件上使用它时,它不起作用。我尝试在创建调度程序之前和创建调度程序之后添加它(通过使用 getEvents,然后修改该数据并使用 resetEvents 更新它们),但这也不起作用..

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 时,它会返回正确的事件 ID,但是当我在编辑时返回未定义。

有人知道我在这里做错了什么吗?

最佳答案

要定位新创建的ScheduleEvent,您需要将event.newSchedulerEvent存储在save函数中。

然后您将能够:

newSchedulerEvent.set("eventid", output.data.EV_ID)

关于javascript - AlloyUI Scheduler - 从数据库加载后添加自定义属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43204759/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com