| Page 1 of 1 | [ 4 posts ] |
|
My app happens to have single instances of a number of views, where I just apply data to them as needed--there's no need to have multiple copies of each. So I've declared the views as preserved in the Y.App() constructor 'views' list. The question: once I've called 'createView' or 'showView', how do I retrieve the instance of the view? I've tried getting the view metadata and examining the 'instance' property, but that never seems to change from null.
Is there a predefined method for this? If not, how would you do it? Dave |
|
Dave,
There currently isn't an API to support this, it is something I've been thinking about and wanting to build in. The way you are currently looking inside of the `views` object and referencing a view's `instance` property is currently the only way to do it. The issue with `instance` being `null` is that the view must be "attached" and therefore become the `activeView` (via the `showView()` method) before it will be registered on the `instance` property. https://github.com/yui/yui3/blob/master ... se.js#L444 The `preserve` config option flags the "detach" process to not destroy the view and to leave `instance` pointing to it. Back to your original task of applying new data to an existing view, this is possibile as of 3.5.1. When calling the `showView()` method, you can pass options, and there are two newer options that you'll be interested in: `update`, and `render`. This gives you control over updating the attributes of an existing view, and whether or not you want to re-render that existing view. The `update` option was added specifically for this use case. Code: app.showView('foo', newData, {update: true}); You can see more details on these options that can be passed to `showView()` here: http://yuilibrary.com/yui/docs/app/#und ... ew-options |
|
Hi David,
You can get current view instance by handling 'activeViewChange' event: myApp.after('activeViewChange', function(evt) { var viewInstance = evt.newVal; }); Also, accordingly to the docs, you can pass callback function to showView method. The callback will be invoked when view is ready to use and its instance will be passed to callback. But I didn't test this way. See http://yuilibrary.com/yui/docs/api/clas ... d_showView. |
|
Dave, Roman brings up a good point, I might have been reading too far into your question. Like Roman pointed out, passing a callback function to `showView()` will result in that function being called with the view instance being passed as an argument.
|
| Page 1 of 1 | [ 4 posts ] |
| You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group