2011-12-27 62 views
2

我已经在这一个现在时:jQuery的原型冲突:表过滤器插件

我内管理平台,一个web应用程序的回报率同时使用jQuery和原型。他们玩得很好,感谢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; 
} 

这显然调用一个原型函数虽然它不应该,但插件代码是最小化,并实际编译与Python,所以没有非最小化版本...

我不是很好的JS,开始时,我很为难,为什么它会调用错误的函数...

PS:我使用

  • 的jQuery 1.4.4
  • 原型1.7
  • 萤火1.8.4用于调试

更新:找到自己的答案,见下文!

+0

嗯..我是新来的。用stackoverflow删除我的文档是否正常? – illiptic 2011-12-27 16:17:48

+0

也许参见http://stackoverflow.com/faq#signatures。 – Blazemonger 2011-12-27 16:25:30

+0

@illiptic - 是的 - 像“预先感谢”或“任何帮助将......”的东西通常被删除作为噪音。 – 2011-12-27 16:28:53

回答

1

我发现在“关闭” lib中的解决方案,用于表过滤器的依赖:

/** 
    * @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. 
    */ 

于是我下载了必要的东西(蟒蛇,闭包编译器......),并自己构建了表格过滤器代码,并将此参数设置为false,并且它可以工作。

现在我有另一个问题,但我应该没问题。如果没有,我会回来问问!

0

尝试包裹插件中:

;(function($) { 
    // This way you secure that $ in this local scope is referring to jQuery and not prototype. 
    // Original plugin goes here.... 
})(jQuery); 
+0

我已经尝试过,抱歉没有提到。 – illiptic 2011-12-28 08:17:27