This is a migrated thread and some comments may be shown as answers.

Get Telerik object using javascript/jQuery

1 Answer 204 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Antonio
Top achievements
Rank 1
Antonio asked on 10 Apr 2012, 03:39 PM
In javascript, $find returns a reference to a Telerik object's exposed client API (e.g., set_enabled, set_autoPostBack, etc.)

Right now, I use this script to get it by the suffix of the id:

var $findByBaseId = function (baseId) {
        return $find($('[id$=' + baseId + ']').attr('id'));
};

Works ok, but seems a little roundabout.  Is there a built in Telerik function that does this?  It seems like I'm scanning the DOM twice.

I'm avoiding the <%%> tags to allow the scripts to be moved to separate files.

1 Answer, 1 is accepted

Sort by
0
Antonio
Top achievements
Rank 1
answered on 10 Apr 2012, 04:29 PM
Never mind.  A little more digging and I found Sys.Application._components which is a dictionary of controls.

var $findByBaseId = function (baseId) {
    var re = new RegExp(baseId + '$');
    for (var key in Sys.Application._components) {
        if (re.test(key)) return Sys.Application._components[key];
    }
    return null;
};

I guess $find doesn't do a DOM scan; looks like Sys.Application.findComponent() just does a lookup.
Tags
General Discussions
Asked by
Antonio
Top achievements
Rank 1
Answers by
Antonio
Top achievements
Rank 1
Share this question
or