This is a migrated thread and some comments may be shown as answers.
Can you fill a LoadOnDemand item from WebService with script?
1 Answer 26 Views
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 04 Nov 2011, 04:08 PM
I'm trying to set up a 'lazy spool', background-cache type system in a very large menu which loads its items from a webservice.
when a menu item opens (and populates its items from a webservice), I'd like to catch the Populated event for that item, and iterate the loaded items and force a populate on them in the background.

I thought calling get_items() would initiate the webservice call - but it doesn't seem to. Open is the only thing which seems to start the webservice request.

Is this technically possible?

function TelerikMenu_OnClientItemPopulated(sender, eventArgs) {
        var items = eventArgs.get_item().get_items();
        for (var i = 0; i < items.get_count(); i++) {
            var item = items.getItem(i);
            if (item != null) {
                item.get_items();
            }
        }
 
}

1 Answer, 1 is accepted

Sort by
0
Andrew
Top achievements
Rank 1
answered on 07 Nov 2011, 02:44 PM
OK, I have made some progress on this, finding the undocumented function _loadChildrenFromWebService in the forums.

function TelerikMenu_ItemOpened(sender, eventArgs) {
    var _i = eventArgs.get_item();
    var items = _i.get_items();
        for (var i = 0; i < items.get_count(); i++) {
            var item = items.getItem(i);
            if (item != null) {
                if (item.get_expandMode() == 1 && item.get_items().get_count() == 0) {
                    item.get_menu()._loadChildrenFromWebService(item);
                }
            }
        }
}


The problem was that if you have a loading template - then the _loadChildrenFromWebService call actually shows the menu expanding... Remove that, and it all works as expected. Now - when a menu item is opened, any un-cached children are preloaded in the background. Now my menu, even though it is webservice populated, is visibly as quick as a menu with preloaded items. Nice one !! :)
Tags
Menu
Asked by
Andrew
Top achievements
Rank 1
Answers by
Andrew
Top achievements
Rank 1
Share this question
or