MultipleViewData.js 1.1 KB

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