YUI 3.4 Model/ModelList Test
by dfederighi
HTML
<script type="text/javascript">
YUI().use('base','node','event','model','model-list', function (Y) {
Y.MyModel = Y.Base.create('MyModel', Y.Model, [], {
idAttribute: 'skuId'
},
{
ATTRS: {
'type':{
value:''
},
'name':{
value:''
},
'skuId':{
value:''
},
'price':{
value:''
}
}
});
Y.MyModelList = Y.Base.create('MyModelList', Y.ModelList, [], {
model: Y.MyModel,
getAll: function() {
this.each(function(model) {
console.log('model:', model);
});
},
doSomething: function(obj) {
alert('did something ' + obj.get('name'));
}
});
Y.MyClass = Y.Base.create('MyClass', Y.Base, [], {
initializer: function() {
},
handleModel: function(data) {
alert('handleModel: ' + data.get('name'));
}
},
{
ATTRS:{}
});
Y.on('domready', function() {
var myClass = new Y.MyClass();
var list = new Y.MyModelList();
list.after('add', function(e) {
myClass.handleModel(e.model);
});
list.add({
'type':'texture',
'name':'foo',
'skuId':'1342',
'price':'$5.35'
});
list.getAll();
});
});
</script>