简体   繁体   English

Fullcalendar Scheduler v4中的eventDrop,oldResource和newResource

[英]eventDrop, oldResource and newResource in fullcalendar scheduler v4

I'm trying to eventually create a php script to update mysql. 我试图最终创建一个PHP脚本来更新mysql。 As I go step by step and try to set the variables and have js behave correctly, I'm having difficulty with changing the 'resource' rooms in the scheduler. 当我一步一步地尝试设置变量并使js正确运行时,我很难更改调度程序中的“资源”室。

If I change the location of the event and change the room, I get a JS alert saying "Title was dropped on to [new time] from [old time]. Old room [oldresource]. New Room [newresource]". 如果我更改事件的位置并更改房间,则会收到JS警报,提示“标题从[旧时间]放到[新时间]。旧房间[oldresource]。新会议室[newresource]”。 That's working well. 很好

However, if I move the event to a location on the same day, I get errors - because info.oldResource and info.newResource are only available IF the event has moved to a NEW resource. 但是,如果我在同一天将事件移到某个位置,则会收到错误消息-因为info.oldResource和info.newResource仅在事件移至新资源时可用。 If they're moving within the same resource, the object doesn't exist. 如果它们在同一资源内移动,则该对象不存在。

I tried working in an IF statement. 我尝试在IF语句中工作。 Console Log shows null, but my if statement is not stopping the processing of the rest of the code. 控制台日志显示为空,但我的if语句并未停止其余代码的处理。 This will eventually (I think) result in the commands not being run correctly - once I pass them to PHP. 最终(我认为)最终将导致命令无法正确运行-一旦将它们传递给PHP。

I plan on having an 'else' statement that does not include oldResource or newResource dialogue to process changes that stay within the same resource. 我计划使用不包含oldResource或newResource对话的'else'语句来处理保留在同一资源内的更改。

My code is as such: 我的代码是这样的:

    eventDrop: function(info) {
if (typeof info.oldResource !=="null")   {
    var oll = console.log(info.oldResource);
    var nww = console.log(info.newResource);
    var oldroom = (info.oldResource.id);
    var newroom = (info.newResource.id);
    var newtitle = info.event.title;
    /*if (oldroom = newroom) {alert ("Same Room");}*/
alert(newtitle + " was dropped on " + info.event.start.toString() + ".Old Time: " + info.oldEvent.start.toString() + ". From: " + oldroom + ". To: " + newroom );

    if (!confirm("Are you sure about this change?")) {
    info.revert();
    }}
},

You don't need typeof here. 您不需要此处的typeof Just write 写吧

if (info.oldResource != null) 

instead. 代替。

Ps if you call typeof on a property that's set to null I would expect the typeof call to return "object", not "null". ps如果您在设置为null的属性上调用typeof ,我希望typeof调用返回“对象”,而不是“ null”。 But like I said, it's irrelevant because you don't need it. 但是就像我说的那样,这无关紧要,因为您不需要它。 Just check for the value null directly. 只需直接检查值null

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM