简体   繁体   English

Sharepoint 2010中的jQuery和JavaScript错误

[英]jQuery and JavaScript error in Sharepoint 2010

i have downloaded a very nice script for realtime filter for sharepoint list: https://instantlistfilter.codeplex.com/ 我已经为共享点列表下载了一个非常好的实时过滤器脚本: https : //instantlistfilter.codeplex.com/

i'm adding the code below. 我在下面添加代码。 and i have two issues with it. 我有两个问题。 1. it is calling Google service, and i wonder if i can avoid that, since i'm not sure my company will be happy to know this list is going to Google each time someone is filtering it. 1.它正在调用Google服务,我想知道我是否可以避免这种情况,因为我不确定我的公司是否会很高兴知道每次有人对其进行过滤时都会将该列表发送给Google。 2. i'm getting error "Object doesn't support this property or method" for line 106 of the code, which causing the ribbon of the site including the "site action" dropdown button to disappear. 2.我收到代码行106的错误“对象不支持此属性或方法”,这导致包含“站点操作”下拉按钮的站点功能区消失。 I know it is related to the "show" command, but i have no clue how can i fix it. 我知道它与“ show”命令有关,但是我不知道如何解决它。

As said above, i'm using sharepoint 2010. To install this code, i created a text document with it in my documents folder, then created below my list a CEW which is linked to that document. 如上所述,我正在使用sharepoint2010。要安装此代码,我在文档文件夹中创建了一个文本文档,然后在列表下方创建了一个链接到该文档的CEW。 this method worked for me in another page with no issues. 此方法在另一页上对我没有任何问题。

Here is the full code as downloaded from the site above: 这是从上面的网站下载的完整代码:

<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>

From what I can see, you're only using the Google code to download jQuery and setup callback when the script gets loaded. 据我所知,脚本加载后,您仅使用Google代码下载jQuery和设置回调。 To avoid downloading from Google, can't you just load a local copy jQuery? 为了避免从Google下载,您是否不能只加载本地副本jQuery?

Download a minimized version of jQuery and upload it to your SharePoint site (Site Assets library or elsewhere). 下载jQuery的最小版本,并将其上传到您的SharePoint网站(站点资产库或其他地方)。

Then in your code above replace this line 然后在上面的代码中替换此行

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

with

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

then you can just replace 那你就可以替换

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
        }
    });
});

with

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

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

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