2017-05-08 182 views
0

我正在嘗試實施Daypilot lite日曆。到目前爲止,它是好的,但我似乎碰到了一些障礙。DayPilot日曆創建事件

我想在calander中創建一個新事件,但我似乎無法將除事件開始和結束之外的任何信息傳遞給daypilot模式。

JavaScript runtime error: 'team' is undefined 

以上這行是我收到的錯誤。 在我的aspx頁面的控制代碼:

<h1>Welcome <asp:Label ID="lblTeam" runat="server"></asp:Label></h1> 
     <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" AppendDataBoundItems="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"> 
      <asp:ListItem Selected="True" Value="0">Select a pitch</asp:ListItem> 
     </asp:DropDownList> 
     <DayPilot:DayPilotCalendar 
      ID="DayPilotCalendar1" 
      runat="server" 
      DataStartField="sess_start" 
      ShowEventStartEnd="true" 
      DataEndField="sess_end" 
      DataTextField="team" 
      DataIdField="BookingId" 
      ClientObjectName="dpc1" 
      TimeRangeSelectedHandling="JavaScript" 
      TimeRangeSelectedJavaScript="timeRangeSelected(start, end, team, pitch)" 
      OnCommand="DayPilotCalendar1_Command" 
      NonBusinessBackColor="Black" 
      HeightSpec="BusinessHoursNoScroll" 
      BusinessEndsHour="20" 
      OnEventMove="DayPilotCalendar1_EventMove" 
      EventMoveHandling="CallBack" 
      /> 

我的JavaScript代碼,將數據發送到模式:

function timeRangeSelected(start, end, team, pitch) { 
     team = document.getElementById('<%= lblTeam.ClientID %>').innerText; 
     var pitchSel = document.getElementById('<%= DropDownList1.ClientID %>'); 
     pitch = pitchSel.options[pitchSel.selectedIndex].value; 
     var modal = new DayPilot.Modal(); 
     modal.top = 60; 
     modal.width = 300; 
     modal.opacity = 70; 
     modal.border = "10px solid #d0d0d0"; 
     modal.closed = function() { 
      if (this.result == "OK") { 
       dpc1.commandCallBack('refresh'); 
      } 
      dpc1.clearSelection(); 
     }; 
     modal.showUrl("New.aspx?start=" + start.toStringSortable() + "&end=" + end.toStringSortable() + "&r=" + team + "&pitch=" + pitch); 
    } 

我需要能夠傳遞的不僅僅是開始和結束的模態。 正如我所提到的,我不太確定這裏發生了什麼,所以任何可以提供的指導將不勝感激。

回答

0

我弄清楚我做錯了什麼,所以我想我會分享它,以防其他人有同樣的麻煩。

以下是我更新的JavaScript代碼。基本上我的問題是關於我在哪裏宣佈用於存儲數據的變量傳遞給模態。當他們需要在函數的範圍之外聲明時,我已經將它們放置在函數中。愚蠢的錯誤,但容易做出。

var team = document.getElementById('<%= lblTeam.ClientID %>').innerText; 
    var pitchSel = document.getElementById('<%= DropDownList1.ClientID %>'); 
    var pitch = pitchSel.options[pitchSel.selectedIndex].value; 

    function timeRangeSelected(start, end, team, pitch) { 
     var modal = new DayPilot.Modal(); 
     modal.top = 60; 
     modal.width = 300; 
     modal.opacity = 70; 
     modal.border = "10px solid #d0d0d0"; 
     modal.closed = function() { 
      if (this.result == "OK") { 
       dpc1.commandCallBack('refresh'); 
      } 
      dpc1.clearSelection(); 
     }; 
     modal.showUrl("New.aspx?start=" + start.toStringSortable() + "&end=" + end.toStringSortable() + "&r=" + team + "&pitch=" + pitch); 
    } 

我希望這可以幫助未來的人。甚至可能是我,你永遠不知道!