mirror of
https://github.com/Leo501/CocosCreatorTutorial.git
synced 2026-05-17 04:10:02 +08:00
44 lines
902 B
JavaScript
44 lines
902 B
JavaScript
cc.Class({
|
|
extends: cc.Component,
|
|
|
|
properties: {
|
|
nodeContent: cc.Node,
|
|
prefabItem: cc.Prefab,
|
|
itemName: ''
|
|
},
|
|
|
|
// onLoad() {
|
|
|
|
// },
|
|
|
|
init(args = {}) {
|
|
this.clear();
|
|
let data = args.data || [];
|
|
let len = data.length;
|
|
for (let i = 0; i < len; i++) {
|
|
this.createItem({
|
|
data: data[i],
|
|
fn: args.fn
|
|
});
|
|
}
|
|
},
|
|
|
|
createItem(args) {
|
|
let data = args.data
|
|
let node = cc.instantiate(this.prefabItem);
|
|
node.script = node.getComponent(this.itemName);
|
|
this.nodeContent.addChild(node);
|
|
node.script.init(data);
|
|
args.fn && args.fn(node.script)
|
|
},
|
|
|
|
clear() {
|
|
this.nodeContent.removeAllChildren();
|
|
},
|
|
|
|
childrenCount() {
|
|
return this.nodeContent.childrenCount;
|
|
}
|
|
|
|
// update (dt) {},
|
|
}); |