2013-12-11 52 views
0

我已經下載了實時過濾器一個非常好的劇本,SharePoint列表: https://instantlistfilter.codeplex.com/jQuery和JavaScript錯誤在SharePoint 2010中

我添加下面的代碼。我有兩個問題。 1.它叫谷歌服務,我不知道我是否可以避免這一點,因爲我不確定我的公司會很高興知道這個名單將在谷歌每次有人過濾它。 2.代碼的第106行出現錯誤「對象不支持此屬性或方法」,導致包含「網站操作」下拉按鈕的網站功能區消失。我知道它與「show」命令有關,但我不知道如何修復它。

如上所述,我使用的是sharepoint 2010.要安裝此代碼,我創建了一個文本文檔,並將其放在我的文檔文件夾中,然後在列表下方創建一個鏈接到該文檔的CEW。這個方法在另一個沒有問題的頁面中爲我工作。

下面是從網站上面下載的完整代碼:

<script src="http://www.google.com/jsapi"></script> 
<script> 
google.load("jquery", "1.2.6"); 
google.setOnLoadCallback(function() { 
$(document).ready(function() 
{ 
    jQuery.extend(jQuery.expr[':'], { 
    containsIgnoreCase: function(a,i,m) {return (a.textContent||a.innerText||jQuery(a).text()||'').toLowerCase().indexOf((m[3]||'').toLowerCase())>=0} 
}); 


$("table.ms-listviewtable tr.ms-viewheadertr").each(function() 
{ 
    if($("td.ms-vh-group", this).size() > 0) 
    { 
     return; 
    } 

    var tdset = ""; 

    var colIndex = 0; 

    $(this).children("th,td").each(function() 
    { 
     if($(this).hasClass("ms-vh-icon")) 
     { 
      // attachment 
      tdset += "<td></td>"; 
     } 
     else 
     { 
      // filterable 
      tdset += "<td><input type='text' class='vossers-filterfield' filtercolindex='" + colIndex + "' /></td>";     
     } 

     colIndex++; 
    }); 

    var tr = "<tr class='vossers-filterrow'>" + tdset + "</tr>"; 

    $(tr).insertAfter(this); 
}); 


$("input.vossers-filterfield") 
    .css("border", "1px solid #7f9db9") 
    .css("width", "100%") 
    .css("margin", "2px") 
    .css("padding", "2px") 
    .keyup(function() 
    {   
     var inputClosure = this; 

     if(window.VossersFilterTimeoutHandle) 
     { 
      clearTimeout(window.VossersFilterTimeoutHandle); 
     } 

     window.VossersFilterTimeoutHandle = setTimeout(function() 
     { 
      var filterValues = new Array(); 

      $("input.vossers-filterfield", $(inputClosure).parents("tr:first")).each(function() 
      {    
       if($(this).val() != "")    
       { 
        filterValues[$(this).attr("filtercolindex")] = $(this).val(); 
       } 
      });  


      $(inputClosure).parents("tr.vossers-filterrow").nextAll("tr").each(function() 
      { 
       var mismatch = false; 

       $(this).children("td").each(function(colIndex) 
       { 
        if(mismatch) return; 

        if(filterValues[colIndex]) 
        { 
         var val = filterValues[colIndex]; 

         // replace double quote character with 2 instances of itself 
         val = val.replace(/"/g, String.fromCharCode(34) + String.fromCharCode(34));       

         if($(this).is(":not(:containsIgnoreCase('" + val + "'))")) 
         { 
          mismatch = true; 
         }      
        } 
       }); 

       if(mismatch) 
       { 
        $(this).hide(); 
       } 
       else 
       { 
        $(this).show(); 
       }  
      });    

     }, 250); 
    }); 
    }); 
}); 
</script> 

回答

0

從我所看到的,你只使用谷歌的代碼時,腳本被加載到下載jQuery和設置回調。爲了避免從谷歌下載,你不能只加載本地副本jQuery?

下載jQuery的最小化版本並將其上傳到您的SharePoint站點(站點資產庫或其他地方)。

然後在上面的代碼替換該行

<script src="http://www.google.com/jsapi"></script> 

<script src="/SiteAssets/{your jquery file name}"></script> 

那麼你可以只更換

google.setOnLoadCallback(function() { 
    $(document).ready(function() { 
     jQuery.extend(jQuery.expr[':'], { 
      containsIgnoreCase: function(a,i,m) {return (a.textContent||a.innerText||jQuery(a).text()||'').toLowerCase().indexOf((m[3]||'').toLowerCase())>=0 
     } 
    }); 
}); 

$(function(){ 
    jQuery.extend(jQuery.expr[':'], { 
     containsIgnoreCase: function(a,i,m) {return (a.textContent||a.innerText||jQuery(a).text()||'').toLowerCase().indexOf((m[3]||'').toLowerCase())>=0 
    } 
}); 
+0

好的。最後 - 以這種方式使用它的這種改變 - 也解決了其他問題! – user3016795

+0

@ user3016795您必須提供更多信息。第106行對我來說不存在,我不能在jsFiddle中運行這段代碼。打開開發人員工具並添加開始步進代碼 – jasonscript