EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Don_Juan on July 07, 2017, 07:24:41 AM



Title: How to detect the type of easyui object, from its id id?
Post by: Don_Juan on July 07, 2017, 07:24:41 AM
Hello to all,
I have a curiosity to which I did not find an answer. ???
Can I detect the type of an object from its name?

Example:

I have an element called myElement.
Object type combobox.
$ ('# myElement') combobox ();

Now, if I have the name (myElement), How do you find that the easyui object type is a combobox?
I hope I have described my curiosity well.
Thank you all  ;D


Title: Re: How to detect the type of easyui object, from its id id?
Post by: jarry on July 07, 2017, 06:30:54 PM
Please call this function to get the object type.
Code:
function getType(target){
var plugins = $.parser.plugins;
for(var i=plugins.length-1; i>=0; i--){
if ($(target).data(plugins[i])){
return plugins[i];
}
}
return null;
}


Title: Re: How to detect the type of easyui object, from its id id?
Post by: Don_Juan on July 10, 2017, 12:41:49 AM
Thank you so much for answering my question.

Var plugins, is an array that contains all type objects; With loop for, check if my target matches one of those in the array plugins.
It is not very clear though what makes $ (target) .data (plugins ).

I insert a control into loop for:

Code:
	for(var i=plugins.length-1; i>=0; i--){
            var ctrl = $(target).data(plugins[i]);
            console.log(i + " TARGET " + target + " is PLUGIN " + plugins[i] + "? " + ctrl);
            if (ctrl){
                return plugins[i];
            }
}

The answer to each call is indefinite, except in the right case, which returns [object, Object]

Thanks