I've been at this one for a while now:
I'm using both jQuery and Prototype within Redmine, a RoR webapp. They play along well thanks to jQuery's noConflict.
I've got jqGrid working fine too.
Now here's my problem: I'm trying to use the Table Filter plugin by PicNet but I get the following js error:
this.each is not a function
@ line 862 of prototype.js
function collect(iterator, context) {
iterator = iterator || Prototype.K;
var results = [];
this.each(function(value, index) {
results.push(iterator.call(context, value, index));
});
return results;
}
It's obviously calling a prototype function while it should not, but the plugin code is minimized, and actually compiled with python, so there's no un-minimized version...
I'm not very good with js to start with, and I'm stumped as to why it calls the wrong function...
PS: I'm using
Update: found the answer myself, see below!
I found the solution in the 'closure' lib, a dependency for Table Filter:
/**
* @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.
*/
So I downloaded the necessary things (python, closure compiler, ... ) and built the Table Filter code myself with this parameter set to false, and it works.
Now I've got another problem, but I should be ok. If not I'll come back here and ask!
Try wrap the plugin in:
;(function($) {
// This way you secure that $ in this local scope is referring to jQuery and not prototype.
// Original plugin goes here....
})(jQuery);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.