Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Ext.id()?

Tags:

extjs

I could not find it in the API documentation or any explanation on different Internet search engine query results.

like image 745
ppecher Avatar asked Feb 21 '11 21:02

ppecher


3 Answers

It's the function that ExtJS uses internally to generate unique IDs for DOM elements that are created by ExtJS. From my console at http://www.sencha.com:

> Ext.id
  function (e,D){return(e=Ext.getDom(e)||{}).id=e.id||(D||"ext-gen")+(++h)}
> Ext.id()
  "ext-gen22"
> Ext.id()
  "ext-gen23"
> Ext.id()
  "ext-gen24"

From the source

See here (scroll down to Public Methods -> id) and here.

/**
     * Generates unique ids. If the element already has an id, it is unchanged
     * @param {Mixed} el (optional) The element to generate an id for
     * @param {String} prefix (optional) Id prefix (defaults "ext-gen")
     * @return {String} The generated Id.
     */
    id : function(el, prefix){
        el = Ext.getDom(el, true) || {};
        if (!el.id) {
            el.id = (prefix || "ext-gen") + (++idSeed);
        }
        return el.id;
    },
like image 139
Matt Ball Avatar answered Oct 04 '22 23:10

Matt Ball


One helpful thing that I've done in the past if you need to generate a unique ID for whatever reason, is just to do something like:

var id = Ext.id();
id = parseInt(id.replace("ext-gen", ""));
return id;

That'll get rid of the "ext-gen" part of the String that Ext.id() returns and give you an int (if you need it).

like image 33
dmackerman Avatar answered Oct 04 '22 23:10

dmackerman


For unique ID number you can also just do:

   var uniqueId = ++Ext.idSeed;
like image 36
Krzysztof Atłasik Avatar answered Oct 04 '22 22:10

Krzysztof Atłasik