JSFiddle - React, Tailwind, and code Playground
by ericf
JavaScript
YUI({filter: 'raw'}).use('model', 'model-list', function (Y) {
var Foo = Y.Base.create('foo', Y.Model, [], {
initializer: function () {
this._models = new Y.ModelList();
this._models.addTarget(this);
},
_getModels: function () {
return this._models;
},
_setModels: function (models) {
return this._models.reset(models);
}
}, {
ATTRS: {
models: {
getter: '_getModels',
setter: '_setModels'
}
}
});
var foos = new Y.ModelList({model: Foo}).reset([
{
id : 1,
type : 'foo',
models: [
{
id : 1,
type: 'submodel'
}
]
}
]);
var foo = foos.getById(1);
foo.get('models').item(0).set('id', 2);
console.log(foo.get('id'));
console.log(foos.getById(1) === foo);
console.log(foos._idMap);
console.log(foo.get('models')._idMap);
});