我的自定义javascript与sharepoint javascript (sharepoint 2010)冲突



我在sharepoint(2010)的自定义应用程序页面中使用自定义javascript文件([mootools-1.2-core.js][1])。我得到类型不匹配错误在wpadder.js(Sharepoint Javascript文件驻留在14/layouts)。谁能提供一个解决这个问题的方法?

我建议在google上搜索类型不匹配错误wpaddder .js - first link = http://labs.steveottenad.com/type-mismatch-on-wpadder-js/

我今天偶然发现了这个问题,因为我犯了同样的错误。Brian Brinley指出的链接(http://labs.steveottenad.com/type-mismatch-on-wpadder-js/)实际上很有帮助,因为它提到:

Sharepoint(可能还有一般的IE)有任何问题尝试扩展Array Prototype的插件/脚本。

我正在处理的代码扩展了 Array.prototype ,以包含 indexOf 方法。

if (!Array.prototype.indexOf) {
    Array.prototype.indexOf = function (obj, start) {
        for (var i = (start || 0); i < this.length; i++) {
            if (this[i] === obj) { return i; }
        }
        return -1;
    }
}

wpadder.js 中的错误在我从代码中删除上述位后立即消失。

作为indexOf方法的替代,我这样写:

// this function returns the index of the first occurrence 
// of the given item in a simple array
function indexOf(array, item, start) {
    for (var i = (start || 0); i < array.length; i++) {
        if (array[i] === item) {
            return i;
        }
    }
    return -1;
}

并将代码中的所有array.indexOf(item)替换为indexOf(array, item)

最新更新