Steven Olmsted![]()
Featured ItemCreates a model list that is the union of two or more other model lists. The new model list stays up to date as the source lists change.
The static method Y.ModelList.union returns a model list that is the union of two or more other model lists.
The first argument determines the type of model list that is created; it may be a constructor function or a string namespace to a constructor function stored on Y. If the first argument is an instance of ModelList, its constructor is used.
Then any number of arguments can follow. The remaining arguments should be ModelList instances or arrays of ModelList instances.
<script src="http://yui.yahooapis.com/3.5.1/build/yui/yui-min.js"></script>YUI({
//Last Gallery Build of this module
gallery: 'gallery-2013.05.10-00-54'
}).use('gallery-model-list-union', function(Y) {
Y.NameModel = Y.Base.create('NameModel', Y.Model, [], {
}, {
ATTRS: {
name: {
value: ''
}
}
});
Y.NameModelList = Y.Base.create('NameModelList', Y.ModelList, [], {
comparator: function (model) {
return model.get('name');
},
model: Y.NameModel
});
var nameModelList0 = new Y.NameModelList().reset([{
name: 'Jeffrey'
}, {
name: 'Emily'
}, {
name: 'Luke'
}]),
nameModelList1 = new Y.NameModelList().reset([{
name: 'Kara'
}, {
name: 'Eric'
}, {
name: 'George'
}]),
nameModelList2 = new Y.NameModelList().reset([{
name: 'Jim'
}, {
name: 'Raymond'
}, {
name: 'Jennifer'
}]),
nameModelListUnion = Y.ModelList.union('NameModelList', nameModelList0, nameModelList1, nameModelList2);
alert(nameModelListUnion.get('name').join(', '));
// Emily, Eric, George, Jeffrey, Jennifer, Jim, Kara, Luke, Raymond
nameModelList1.add({
name: 'Sarah'
});
nameModelList2.add({
name: 'Matthew'
});
alert(nameModelListUnion.get('name').join(', '));
// Emily, Eric, George, Jeffrey, Jennifer, Jim, Kara, Luke, Matthew, Raymond, Sarah
nameModelList0.reset();
alert(nameModelListUnion.get('name').join(', '));
// Eric, George, Jennifer, Jim, Kara, Matthew, Raymond, Sarah
});
© 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