我在这方面已经有一段时间了:
我在 Redmine(一个 RoR 网络应用程序)中同时使用 jQuery 和 Prototype。由于 jQuery 的 noConflict,它们可以很好地配合。
我的 jqGrid 也能正常工作。
现在这是我的问题:我正在尝试使用 Table Filter plugin by PicNet 但我收到以下 js 错误:
this.each is not a function
@prototype.js的第862行
function collect(iterator, context) {
iterator = iterator || Prototype.K;
var results = [];
this.each(function(value, index) {
results.push(iterator.call(context, value, index));
});
return results;
}
明明是在调用原型(prototype)函数,其实不应该,但是插件代码是最小化的,而且实际上是用python编译的,所以没有非最小化版本...
一开始我对 js 不是很好,我很困惑为什么它会调用错误的函数...
P.S: 我正在使用
- jQuery 1.4.4
- 原型(prototype) 1.7
- 用于调试的 Firebug 1.8.4
更新:自己找到答案,见下文!
最佳答案
我在“闭包”库中找到了解决方案,它是表过滤器的依赖项:
/**
* @define {boolean} NATIVE_ARRAY_PROTOTYPES indicates whether the code should
* rely on Array.prototype functions, if available.
*
* The Array.prototype functions can be defined by external libraries like
* Prototype and setting this flag to false forces closure to use its own
* goog.array implementation.
*
* If your javascript can be loaded by a third party site and you are wary about
* relying on the prototype functions, specify
* "--define goog.NATIVE_ARRAY_PROTOTYPES=false" to the JSCompiler.
*/
所以我下载了必要的东西(python,闭包编译器,...)并自己构建了表过滤器代码,并将此参数设置为 false,并且它起作用了。
现在我遇到了另一个问题,但我应该没问题。如果没有我会回来问!
关于javascript - jQuery 原型(prototype)冲突 : table filter plugin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8646729/