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

How to attach an "onload" to a certain div (data-role/data-title)?

2 Answers 349 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Klaus
Top achievements
Rank 1
Klaus asked on 31 Mar 2013, 09:42 PM
I tried to search but the search seems to search the entire forum and I couldn't limit it to just "mobile", so I'm trying my luck with a thread instead.

I'm currently using the trial version, since I'm new into PhoneGap. Not sure yet if I will go ahead with KendoUI Mobile or if I'll give jQuery Mobile a shot too. 

My problem right now is that I have a "div page" on which I want an onload event to fire, when that page is being pulled up.

Here's the div:

<div data-role="view" id="tabstrip-log" data-title="Activitylog" data-layout="mobile-tabstrip">
... some stuff here.
</div>

When I click the button in the tabstrip for #tabstrip-log, then the div above appears, and then I want to also call a function that downloads JSON data and puts it into the div in li's etc. I have that part down, with a manual button. I just want it so that the function is called automatically whenever #tabstrip-log loads.

I don't want the data loaded when the app is started, because then I can just attach it to <body onload="json()">, rather I only want that data pulled when that particular div is shown.

Any hints?

Thanks in advance.

2 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 02 Apr 2013, 12:50 PM
Hello Klaus,

Thank you for interest in KendoUI Mobile.
Mobile View events are listed here. I believe that you are looking for the init or show event. The first one will fire only once, when the View is initialized. Second one will fire every time when the View becomes visible.

You can hook up to the event via data-attribute:
<div data-role="view" id="tabstrip-log" data-title="Activitylog" data-layout="mobile-tabstrip" data-init="onInit">
... some stuff here.
</div>

Where "onInit" is a JavaScript function.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Klaus
Top achievements
Rank 1
answered on 02 Apr 2013, 01:36 PM
That did the trick, thanks :)
Tags
General Discussions
Asked by
Klaus
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Klaus
Top achievements
Rank 1
Share this question
or