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

destroy() method of kendo.mobile.ui.View

3 Answers 181 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Gurumurthy
Top achievements
Rank 1
Gurumurthy asked on 07 Aug 2013, 11:59 AM
Hello - 

This question pertains to the usage of the destroy() method of kendo mobile view object. We have an application that starts off displaying a login screen (login-view), where a user enters username/password to view a "dashboard" screen (dashboard-view). Here is the index.html markup showing the login-view and the dashboard-view - for brevity's sake I am only showing the relevant portions of the code, and oversimplifying it.

...
...
<div data-role="view" id="login-view" data-layout="login-layout" data-init="login-init">
   <div id="login-view-content" data-role="content"></div>
</div>
 
<div data-role="view" id="dashboard-view" data-layout="default-layout" data-init="dashboard-init">
   <div id="dashboard-view-content" data-role="content"></div>
</div>
...
...
The app is initialized as:
this.kendoApp = new kendo.mobile.Application(document.body, { initial: "login-view" });
In the data-init methods of both views, we insert content into the respective content divs ("login-view-content" and "dashboard-view-content"). When the user logs out, the app navigates to the login-view. The problem we are facing is when a second (different) user logs in, the first user's content is still displaying. (Note that the data-init methods are not called for the second user since those views have already been inititalized. We tried solving this problem by destroying the dashboard view and emptying out the contents at the time of logging out:

$("#dashboard-view").data("kendoMobileView").destroy()
$("#dashboard-view-content").empty(); // also tried without this line.
On the second login, we recreated the view as:

$("#dashboard-view").kendoMobileView();
We were expecting this to fire the dashboard-init event where we could insert the second user's content, but that wasn't the case - dashboard-init never gets called again. It seems intuitive that when a view is destroyed and recreated, then the corresponding data-init should be called. Is there a mechanism in the kendo.mobile's API that could address this problem. If not, what approach should be taken in this situation as recommended by Kendo's best practices? 

Regards,
Sundar

3 Answers, 1 is accepted

Sort by
0
Petyo
Telerik team
answered on 09 Aug 2013, 10:21 AM
Hi,

The destroy method is not meant to be called on widgets that will be re-instantiated later. In addition to that, instantiating a mobile view using the jQuery plugin is not fully supported, too. 

The simplest approach in this case would be to perform a regular html document reload on logout, which will re-instantiate the mobile application and remove all in-memory data.

Regards,
Petyo
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
ANN
Top achievements
Rank 1
answered on 08 Aug 2014, 05:02 PM
Hi Petyo,

I have a similar behavior in my app where different views need to be completely reinitialized. However, all the views that need to be reinitialized at a given time are those that belong to a single html file and that file needs to be reloaded. when I call a view in that file. How do I achieve that during a navigate request.

Thanks !!
0
Petyo
Telerik team
answered on 12 Aug 2014, 07:39 AM
Hi Ann,

In general, the reload view option should do what you are looking for. However, it is designed to work with one view per remote request, since the remote view does not keep track of its auxiliary views.

Regards,
Petyo
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
General Discussions
Asked by
Gurumurthy
Top achievements
Rank 1
Answers by
Petyo
Telerik team
ANN
Top achievements
Rank 1
Share this question
or