2017-02-22 33 views
0

有沒有辦法將信息添加到asp:TreeView中,方法是通過JavaScript/Jquery訪問它?我的問題:我必須通過JQuery/Javascript(在客戶端)阻止asp:TreeView中的複選框可以在不同的子類別(或通過構造型前綴分組的父類節點)中選擇。當我向$(this).next()。text()請求TreeNode-Text時,它已經工作了,因爲它們在類別中有一個前綴(原型),但現在我必須隱藏該信息並且不能使用它去檢查。<asp:TreeView>通過JavaScript/JQuery向treenode添加更多信息?

$("[id*=TreeView1] input[type=checkbox]").bind("click", function() { 

     var isChecked = $(this).is(":checked"); 

     if (isChecked) { 
      zuletztSelektiert = zuletztSelektiert + $(this).next().text(); 
     } 
     else { 
      zuletztSelektiert = zuletztSelektiert.replace($(this).next().text(), ''); 
     } 

     if (zuletztSelektiert != '') { 
      // Welcher Stereotyp ist selektiert? 
      var stereotype = zuletztSelektiert.substring(zuletztSelektiert.indexOf('«') + 1, zuletztSelektiert.indexOf('»')); 

      $("[id*=TreeView1] input[type=checkbox]").each(function() { 
       var currentStereotype = $(this).next().text().substring($(this).next().text().indexOf('«') + 1, $(this).next().text().indexOf('»')); 

       if (currentStereotype != stereotype) { 
        var isChecked2 = $(this).is(":checked"); 

        if (isChecked2) { 
         $(this).removeAttr("checked"); 
         zuletztSelektiert = zuletztSelektiert.replace($(this).next().text(), ''); 

         alert('It is not possible to select elements of different stereotypes. \n\n Selected Items:\n' + zuletztSelektiert); 
        } 
       } 

      }); 

     } 
    }); 
+0

嗨!通過向目標URL添加原型來解決它,因爲我沒有找到方法。 –

回答

0

好了,因爲沒有人知道答案,我只是做了它通過增加刻板印象GET-帕拉姆的鏈接目標URL,並在樹節點導航到-Tag

$("[id*=TreeView1] input[type=checkbox]").bind("click", function() { 

     var selectedStereoType = $.trim($(this).next().prop("href").substring($(this).next().prop("href").indexOf("=") + 1)); 
     //return; 

     var isChecked = $(this).is(":checked"); 

     if (isChecked) { 
      //zuletztSelektiert = zuletztSelektiert + $(this).next().text(); 
      zuletztSelektiert = zuletztSelektiert + selectedStereoType; 
     } 
     else { 
      //zuletztSelektiert = zuletztSelektiert.replace($(this).next().text(), ''); 
      zuletztSelektiert = zuletztSelektiert.replace(selectedStereoType, ''); 
     } 

     if (zuletztSelektiert != '') { 
      // Welcher Stereotyp ist selektiert? 
      //var stereotype = zuletztSelektiert.substring(zuletztSelektiert.indexOf('«') + 1, zuletztSelektiert.indexOf('»')); 
      var stereotype = selectedStereoType; 
      var letzteMeldung = ''; 

      $("[id*=TreeView1] input[type=checkbox]").each(function() { 
       //var currentStereotype = $(this).next().text().substring($(this).next().text().indexOf('«') + 1, $(this).next().text().indexOf('»')); 
       var currentStereotype = $.trim($(this).next().prop("href").substring($(this).next().prop("href").indexOf("=") + 1)); 

       if (currentStereotype != stereotype) { 
        var isChecked2 = $(this).is(":checked"); 

        if (isChecked2) { 
         $(this).removeAttr("checked"); 
         zuletztSelektiert = zuletztSelektiert.replace($.trim($(this).next().prop("href").substring($(this).next().prop("href").indexOf("=") + 1)), ''); 

         letzteMeldung='It is not possible to select elements of different stereotypes. \n\n Selected Items: ' + zuletztSelektiert; 
        } 
       } 

      }); 

      if (letzteMeldung != '') alert(letzteMeldung); 

     } 
    }); 

這是怎麼了我在C#.NET中做了它 treeNode.NavigateUrl =「URL?stereotype =」+ stereotype;