Skip to content

Instantly share code, notes, and snippets.

@ericf
Created September 15, 2011 05:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericf/1218596 to your computer and use it in GitHub Desktop.
Save ericf/1218596 to your computer and use it in GitHub Desktop.
YUI().use('model', 'model-list', function (Y) {
Y.Tag = Y.Base.create('tag', Y.Model, [], {}, {
ATTRS: {
name: {}
}
});
Y.Tags = Y.Base.create('tags', Y.ModelList, [], { model: Y.Tag });
Y.Post = Y.Base.create('post', Y.Model, [], {
_setTags: function (tags) {
// Make sure we just have a native Array of Tag instances.
tags = Y.Array(tags instanceof Y.ModelList ? tags.toArray() : tags);
// Update the Tags instance with the new tags.
this.get('tags').reset(tags);
}
}, {
ATTRS: {
title: {},
body : {},
tags : {
value : new Y.Tags,
setter: '_setTags'
}
}
});
var post = new Y.Post({
title: 'Foo Post',
body : 'Bla bla bla…',
tags : [
{ name: 'YUI' },
{ name: 'App Framework' }
]
});
post.get('tags').add({ name: 'JavaScript' });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment