UserPackPage.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. const dataItemInfo = require('../data/item');
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. packItemPrefab: cc.Prefab,
  6. pageLayout: cc.Layout,
  7. },
  8. // LIFE-CYCLE CALLBACKS:
  9. onLoad () {
  10. },
  11. init(array,page) {
  12. for (var i = 0; i < 20; i++) {
  13. let item = cc.instantiate(this.packItemPrefab);
  14. item = item.getComponent('UserPackItem');
  15. if (i < array.length) {
  16. let itemInfo = array[i];
  17. let count = itemInfo.count;
  18. dataItemInfo.forEach(info => {
  19. if (info.id == itemInfo.itemId) {
  20. itemInfo = info;
  21. }
  22. });
  23. itemInfo.count = count;
  24. item.init(i,page,itemInfo);
  25. } else {
  26. item.init(i,page);
  27. }
  28. this.pageLayout.node.addChild(item.node);
  29. }
  30. },
  31. onDisable () {
  32. for (let child of this.pageLayout.node.children) {
  33. if (cc.isValid(child)) {
  34. child.destroy();
  35. }
  36. }
  37. },
  38. start () {
  39. },
  40. // update (dt) {},
  41. });