Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/402.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AlloyUI调度程序-从数据库加载后添加自定义属性_Javascript_Jquery_Events_Scheduler_Yui - Fatal编程技术网

Javascript AlloyUI调度程序-从数据库加载后添加自定义属性

Javascript AlloyUI调度程序-从数据库加载后添加自定义属性,javascript,jquery,events,scheduler,yui,Javascript,Jquery,Events,Scheduler,Yui,我已经为这个问题挣扎了几天了,基本上我要完成的是为从数据库加载的每个事件添加一个自定义属性。 我搜索了很长一段时间,在其他函数中找到了addAttr函数。在添加和保存新事件时,此函数可以很好地工作,但在我从数据库加载的事件上使用它时,它显然不起作用。我尝试在创建调度器之前和创建调度器之后添加它(通过使用getEvents,然后修改数据并使用resetEvents更新数据),但这也不起作用 function Schedule( boundingbox, events ) { var sel

我已经为这个问题挣扎了几天了,基本上我要完成的是为从数据库加载的每个事件添加一个自定义属性。 我搜索了很长一段时间,在其他函数中找到了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时,它会返回正确的eventid,但当我在“编辑”中执行此操作时,它会返回未定义的


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

要针对新创建的
ScheduleEvent
,您需要将
事件.newSchedulerEvent
存储在save函数中

然后您将能够:

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

要以新创建的
ScheduleEvent
为目标,您需要在save函数中存储
event.newSchedulerEvent

然后您将能够:

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