2013-04-18 73 views
0

我有一個問題,我試圖找出爲什麼我必須按兩次彈出按鈕的「確定」按鈕使其消失。我可以從我的代碼中看到的,我只是隻有一個alert語句,仍然它的行爲就好像我可能有意外稱爲被觸發兩次變更事件的兩個警示語句jquery彈出不得不按兩次「OK」兩次,以使其消失

function intialiseKendoGrid(date) { 
    gridResult = $('#grid').kendoGrid({ 
     scrollable: { 
      virtual: true 
     }, 
     navigatable: true, 
     groupable: true, 
     sortable: true, 
     selectable: "row", 
     pageable: true, 

     pageable: { 
      input: true, 
      numeric: false 
     }, 

     resizable: true, 
     reorderable: true, 
     filterable: { 
      extra: false 
     }, 
     columns: [{ 
      field: "DealNumber", 
      width: 150, 
      title: "DealNumber", 

      filterable: { 
       operators: { 
        string: { 
         startswith: "Starts With", 
         contains: "Contains" 
        } 
       } 

      }, 
     }, 
     { 
      field: "DealIssuer", 
      width: 150, 
      title: "Issuer", 
      filterable: { 
       operators: { 
        string: { 
         startswith: "Starts With", 
         contains: "Contains" 
        } 
       } 
      }, 
      //template: "<a href='http://manager.dealogic.com/ManagerV3/CPCortex/Default/${DealNumber}'>${DealNumber}</a>" 
      template: "<a>${DealIssuer}</a>" 

     }, { 
      field: "Ticker", 
      width: 150, 
      title: "Ticker", 
      filterable: { 
       operators: { 
        string: { 
         startswith: "Starts With", 
         contains: "Contains" 
        } 
       } 
      }  
     }, { 
      field: "DealExchange", 
      width: 150, 
      title: "Exchange", 
      filterable: { 
       operators: { 

        string: { 
         startswith: "Starts With", 
         contains: "Contains" 
        } 
       } 
      } 
     }, { 
      field: "DealType", 
      width: 150, 
      title: "Type", 
      filterable: { 
       operators: { 
        string: { 
         startswith: "Starts With", 
         contains: "Contains" 
        } 
       } 
      } 

     }, { 
      field: "DealValue", 
      width: 150, 
      title: "Value ($m)", 
      filterable: { 
       operators: { 
        string: { 
         startswith: "Starts With", 
         contains: "Contains" 
        } 
       } 
      }, 
      /* template: '#= kendo.culture("en-US");kendo.toString(${DealValue/1000000},"p")#' */ 

      template: '#= kendo.toString(DealValue,"c2") #' 

     }, { 
      field: "DealStatus", 
      width: 150, 
      title: "Status", 
      filterable: { 
       operators: { 
        string: { 
         startswith: "Starts With", 
         contains: "Contains" 
        } 
       } 
      } 

     }, { 
      field: "DealPricingCompletionDate", 
      width: 230, 
      title: "DealPricingCompletionDate", 
      format: "{0:dd/MM/yyyy}", 
      filterable: { 
       ui: "datetimepicker", 
       operators: { 
        date: { 
         gt: "After", 
         lt: "Before", 
         eq: "Equals" 
        }, 
        messages: { 
         filter: "Apply", 
         clear: "Clear" 
        } 
       } 

      } 
     }, 
     ], 

     change: function() { 
      var text = ""; 
      var grid = this; 
      grid.select().each(function() { 
       var dataItem = grid.dataItem($(this)); 
       text += "DealNumber: " + dataItem.DealNumber + "\n" + "Issuer: " + dataItem.DealIssuer + "\n" + "Ticker: " + dataItem.Ticker + "\n" + "Type: " + dataItem.DealType + "\n" + "Value: " + dataItem.DealValue + "\n" + 
        "Status " + dataItem.DealStatus + "\n" + "DealPricingCompletionDate: " + kendo.toString(dataItem.DealPricingCompletionDate, "dd/MM/yyyy"); 
      }); 
      alert(text); 
     }, 
     height: 700 
    }).data("kendoGrid"); 
+2

其中是調用'change'方法嗎? – karthikr

+0

只要用戶選擇網格中的某一行,它就會自動調用。這就是爲什麼有一個屬性被稱爲可選:「行」, – Sike12

回答

1

經過長時間的耽擱,現在已經被破解。 我所要做的就是使用SetTimeOut Method by timeout作爲0意味着不指定任何時間參數。 所以固定代碼是

function onRowSelected(e) { 
     e.preventDefault(); 
     console.log(e.sender); 
     var text = ""; 
     var grid = this; 
     grid.select().each(function() { 
      var dataItem = grid.dataItem($(this)); 
      text += "DealNumber: " + dataItem.DealNumber + "\n" + "Issuer: " + 
       dataItem.DealIssuer + "\n" + "Ticker: " + dataItem.Ticker + "\n" + "Type: " + dataItem.DealType + "\n" + "Value: " + dataItem.DealValue + "\n" + 
       "Status " + dataItem.DealStatus + "\n" + "DealPricingCompletionDate: " + kendo.toString(dataItem.DealPricingCompletionDate, "dd/MM/yyyy"); 
     }); 
     setTimeout(function() { alert(text) },0); 

    } 
3

,而且由於alert()被綁定到變化事件時,它也會彈出兩次。請參閱change event documentation。它是「當用戶在網格中選擇表格行或單元格時觸發的。」

也許它被解僱了兩次,一次是針對行和一次針對細胞?雖然我看到你有selectable: "row",所以它應該只爲該行開火。

將您的更改事件更新爲change: function (e) { console.log(e); },並查看它在調試控制檯中輸出的內容。這會給你一個暗示它觸發的元素。

然後,您可以嘗試將e.preventDefault();添加到您的更改事件中,以阻止任何其他事件被觸發。

+0

有沒有辦法阻止這種情況發生兩次,因爲只要我選擇一行,自動觸發更改事件 – Sike12

+0

嗨@nullability我試着看起來像它得到通過單元格點擊觸發,我發現它只能觸發一次。我也嘗試了e.preventDefault(),但仍然必須按OK按鈕兩次以使彈出消失 – Sike12

+0

嗨@nullability現在已被修復。感謝您的時間和精力。真的很感激它。保持良好的工作 – Sike12