EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Onegin on July 07, 2011, 11:39:44 AM



Title: determining object type
Post by: Onegin on July 07, 2011, 11:39:44 AM
Is it possible to determine what UI object is attached to a DOM node?
e.g.

$('#tt').datagrid({config...})

how can I check that UI object attached to $('#tt') is actually datagrid? Option object does not return it.
I use to reload data in grids using single common function, but have troubles to determine if it is datagrid or treegrid.


Title: Re: determining object type
Post by: stworthy on July 07, 2011, 06:50:29 PM
The all plugin such as datagrid and treegrid is same as other jQuery plugins(find, html, val, etc), they all extend with jQuery.fn object.
There is no efficient way to determine the object type, but you can add a type option while creating your object and then read this type from the 'options' object or directly to determine its object like this:

Code:
var target = $('#tt').get(0); // the DOM object
if ($.data(target,'treegrid')){
  alert('treegrid');
} else if ($.data(target,'datagrid')){
  alert('datagrid')
}


Title: Re: determining object type
Post by: Onegin on July 08, 2011, 01:08:23 AM
Thank you. Worked. ::)