MultipleViewData.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. cc.Class({
  2. initRoot (rootNode) {
  3. this.rootNode = rootNode;
  4. this.views = [];
  5. this.curViewType = null
  6. return this;
  7. },
  8. addViewData(viewType) {
  9. this.views.push({type:viewType, view:null, initing:false})
  10. },
  11. createOrShowView(type, parent) {
  12. let viewData = this.views[type]
  13. for (let vd of this.views) {
  14. if (vd.view == null) {
  15. continue
  16. }
  17. vd.view.active = false;
  18. }
  19. if (viewData.initing) {
  20. return
  21. }
  22. if (viewData.view != null) {
  23. viewData.view.active = true;
  24. return
  25. }
  26. viewData.initing = true
  27. let self = this
  28. this.rootNode.createComponent(viewData.type, parent, null, function(node, status) {
  29. if (status != 'ok') {
  30. return
  31. }
  32. viewData.view = node
  33. viewData.initing = false
  34. node.active = self.curViewType == type
  35. })
  36. }
  37. })