0

Passing parameters to a view

Could someone provide me with a code example of loading a view, passing parameters to it and then retrieving those parameters within the loaded view?

by
4 Replies
  • QUOTE (Jonathan @ Jun 8 2009, 07:54 AM) <{POST_SNAPBACK}>
    Could someone provide me with a code example of loading a view, passing parameters to it and then retrieving those parameters within the loaded view?


    Hi Jonathan,

    Please refer to http://developer.yahoo.net/forum/index.php?showtopic=1427


    Hope it can help you.
    0
  • QUOTE (Jonathan @ Jun 8 2009, 07:54 AM) <{POST_SNAPBACK}>
    Could someone provide me with a code example of loading a view, passing parameters to it and then retrieving those parameters within the loaded view?


    To load the view:

    CODE
    KONtx.application.loadView('view-Id', { foo: 33, bar: 42, baz: "Hello World!" });


    Inside the loaded view, to access those variables, they will be available as:

    CODE
    this.persist.foo // is 33
    this.persist.bar // is 42
    this.persist.baz // is Hello World!


    inside the view class (and should be operated on in the updateView() call).

    If any of this doesn't make sense, let me know and I would be happy to explain further.

    -Jeremy
    0
  • QUOTE (Jeremy Johnstone @ Jun 8 2009, 08:31 PM) <{POST_SNAPBACK}>
    inside the view class (and should be operated on in the updateView() call).


    Can they not also be operated on in the createView() call?
    0
  • QUOTE (Jonathan @ Jun 9 2009, 08:53 AM) <{POST_SNAPBACK}>
    Can they not also be operated on in the createView() call?


    Yes, they can, but you _must_ also pay attention to them inside updateView(). You only get a createView() the first time the view is created (unless it's garbage collected based on non-use), updateView() is called each time.

    A real world example:

    In the Finance widget when you select the Yahoo! row in the list, we load up the detail view passing in the stock symbol for the view to load. The first time, createView() gets called. If I then hit back in the sidebar and then go and select Apple from the list, the same view gets reloaded, but this time only updateView() gets called and the new symbol will be available in this.persist.

    -Jeremy
    0

Recent Posts

in General - Yahoo! TV Widgets