Created
September 15, 2011 05:13
-
-
Save ericf/1218596 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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