| Page 1 of 1 | [ 8 posts ] |
|
I have discovered after I got my example from a previous post working (viewtopic.php?p=32873), another problem. This may be a "feature" and not a "bug", but it seems like it's more of a bug to me.
In order for a Y.View to bind to it's container (if the container is already an existing DOM element), the 'container' attribute must be accessed using the attribute getter first. My use of Y.View might be somewhat unconventional since I am creating a logical view rather than constructing a new DOM element sub-tree, so this might not have come up in testing or traditional use. This example is working, but only because I have put a "this.get('container')" into the render() method. If I comment this out, the DOM events described in "events:" do not fire (or bind, I am assuming): http://www.0x743.com/view-event-3.5.1.html I discovered this because when debugging, I put an alert to give me the contents of the container. When I'd do that, the event would be heard and the proper handler would fire. When I commented out the alert, it would not work. Upon further investigation, I determined that if I did a this.get('container') or myInstance.get('container') - even without the alert, the events would be handled properly. This might be reasonable behavior if you're creating and appending a DOM subtree to the main DOM, but if you're attaching to an existing DOM element it's not; even if it could be argued that it's reasonable behavior, it is unexpected (inconsistent) and I couldn't find it documented anywhere. Thanks! Brett |
|
Hi Brett,
All the views I've created always had a container set to a DOM node. I'm not sure what you mean by a logical view and what your use case is such that it requires this logical DOM-less view. Could you expand on this point? Thanks. |
|
I am attaching the View to an existing node rather than creating one. The reason is because the client side templating is way to slow for my application.
So, when I attach to an existing DOM node rather than create one just for the View, I find that I have to make an attribute call to 'container' before the events described in "events:" are bound to the 'container'. if I create a new DOM node just for the View, I have to make no such "get" call to 'container'. Make sense? See my example. Brett |
|
Here's how I attach to an existing DOM element:
Code: var searchView = new Y.ns.companySearchView({ model: company, container : Y.one('#searchbox'), }); Note below, that in order for the events described in "events: {}" to bind to the 'container', I have to call this.get('container') in the render() method. Code: YUI.add('company-search-view', function(Y) { Y.namespace('ns').companySearchView = Y.Base.create('companySearchView', Y.View, [], { events: { '#findButton': { click: '_findCompany', }, }, _findCompany: function(e) { alert('hi'); }, initializer: function() { this.get('model').after('change', this.render, this); this.get('model').after('destroy', this.destroy, this); }, render: function() { var container = this.get('container'); //<-- this is required for events to bind to 'container' when it's an existing DOM node }, }, { ATTRS: { } }) }, '0.1', { requires: ['view', 'node', 'json-stringify', 'io'] }); |
|
This is pretty odd. I'm able to reproduce your use case and like you say, I have to call the get container attribute in order for the events to bind to the view. How odd...
Sorry I can't be of help. |
|
I'm looking through my code base and all the views I created make the call to container to set the HTML. So that's why I guess I never ran into this issue.
|
|
There is currently a ticket open for this:
http://yuilibrary.com/projects/yui3/ticket/2532304 Feel free to add your comments/CC yourself on it. |
|
Thank you, I just added a link to this thread in case it's helpful.
Brett |
| Page 1 of 1 | [ 8 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