hey, glad I was able to help. I would assign those nodes as object
properties of the view, like "this.container" or whatever a good name might
be.
You might want to separate creating the view from binding it to the DOM.
YUI documents this exhaustively in their Widget user guide, all the widgety
libraries do something analogous.
Anyway, instead of directly toggling classes, you can wrap that in view
object methods like _showList or _hideForm or whatever. So your hideFoo
method might say "this._foo.toggleClass('hidden')," as a lazily constructed
example.
That opens the door to separating event handler functions, like _onClick,
from the UI manipulation functions, like _hideForm. Sweet.
>From there, you can see how it's analogous to think in terms of binding to
objects, instead of DOM nodes, and subscribe to events published by those
objects, without using the DOM at all. That's where MVC comes in: when the
model updates itself, it notifies the subscribing views, which check (or
are passed) the model's data and redraw themselves accordingly.
This is how big JS apps tend to be structured; it's pretty different from
storing state in the DOM.
I havent taken a look at your knockout.js file, but ping if you have
specific questions about it.
On Nov 14, 2011 3:21 PM, "Andrew Dodson" <[email protected]> wrote:
Thanks *Jared*, that makes sense
AppView now passes an object like so...
window.App = new AppView({
$searchresults: $("body > ul"),
$favourites : $("footer ul"),
$input : $("form input"),
$body : $("body"),
$preview : $("article")
});
and call them through *this.options* e.g....
*
*
*this.options.$body.addClass('results'); *
*
*
However its not totally DOM independent as i'm still manipulating the class
names. Is there an alternative to this?
FYI: I've rewritten the script using knockout.js (
http://mrswitch.github.com/pic-n-flick/knockout/) which has been awesome,
i've been able to totally remove any DOM operations from my script.js file.
Perhaps this is easy to achieve in backbone?
A
On Mon, Nov 14, 2011 at 10:18 PM, Jared Hirsch <[email protected]>
wrote:
>
> The search func...
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]