[ 3 posts ]

Ryan Cannon

YUI Contributor

  • Username: rcanine
  • Joined: Thu Apr 22, 2010 1:40 pm
  • Posts: 23
  • Location: Culver City, CA
  • Twitter: rcanine
  • GitHub: RCanine
  • Gists: RCanine
  • Offline
  • Profile

Y.Base and Y.substitute

Post Posted: Wed May 05, 2010 2:40 pm
+0-
Some background: I'm coming from Prototype and am used to using Prototype's Template class for doing repeated updates from a stored template. Y.substitute seems like the correct method to use for this, but I'm having trouble wrapping my head around it.

Is there an example of using the third argument, the function callback, in the wild?

Also, I noticed that substitute doesn't play well with YUI 3's OOP infrastructure, e.g.

[gist=391551]Substitute doesn't get properties of YUI objects.[/gist]

Any advice on making these two work together better, rather than writing a toObject() serializer?

Edit: Here's the gist. Unsure why it's not working inline.

Satyen Desai

YUI Developer

  • Username: sdesai
  • Joined: Tue Dec 09, 2008 4:17 pm
  • Posts: 302
  • GitHub: sdesai
  • Gists: sdesai
  • YUI Developer
  • Offline
  • Profile

Re: Y.Base and Y.substitute

Post Posted: Wed May 05, 2010 3:06 pm
+0-
Re: your gist:

It's because test.foo doesn't exist (foo is an attribute, not a .property).

You can change your last substitute call to:

Y.substitute("{foo}", test.getAttrs())

getAttrs() is effectively your toObject() serializer in this case.

Hope that helps,
Satyen

Ryan Cannon

YUI Contributor

  • Username: rcanine
  • Joined: Thu Apr 22, 2010 1:40 pm
  • Posts: 23
  • Location: Culver City, CA
  • Twitter: rcanine
  • GitHub: RCanine
  • Gists: RCanine
  • Offline
  • Profile

Re: Y.Base and Y.substitute

Post Posted: Wed May 05, 2010 3:25 pm
+0-
Thanks, that's a big help. We're still struggling with using more complex templates (e.g. accessing properties of properties), but this works for subclasses of Y.Base.
  [ 3 posts ]
Display posts from previous:  Sort by  
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