0
votes

In Sencha Touch 2, on a controller, I have the following code:

onRedirectToCartCommand: function(view, shoppingCartData) {
        console.log('ProductViewController - onRedirectToCartCommand()');
        console.log(shoppingCartData)
        this.redirectTo('cart');
    }

Upon triggering an event, I use the redirectTo function, which tells Sencha's router to create a new view and add it into the viewport.

Do you know a way to send an object along with the redirectTo function over to the router (which is another controller which handles the site-s routes)?

1

1 Answers

0
votes

If you want to take an object from one place to another you have a couple possibilities :

  • Call a function of the destination, with your object in argument

The most obvious answer, usefull when you want to create a flow, and if that object is just necessary in these two places.

  • Store your object in a static place (either a singleton, or a static field of a class)

Good for storing stuff you'll be likely using several times in different places. Just create a class with the singleton property, and put objects in it as if they where fields (MySingleton.set('objectName', object)).

  • Local Storage

You can use the HTML 5 Api local storage (sencha has a way to do it easily) and store your object in the local cache of the device. It's good for things that needs to stay (like a session).

Then you just have to retrieve the object from either the function, the singleton class, or the local storage.