SequenCreateView.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. let MultipleViewData = require('MultipleViewData')
  2. cc.Class({
  3. extends: MultipleViewData,
  4. initRoot (rootNode) {
  5. this._super(rootNode);
  6. this.datas = [];
  7. this.createIndex = 0;
  8. return this;
  9. },
  10. addDatas(datas) {
  11. this.datas = datas
  12. },
  13. getCells() {
  14. return this.cells;
  15. },
  16. startCreate(type, parent, cb) {
  17. this.createIndex = 0
  18. this.cells = [];
  19. parent.removeAllChildren()
  20. this.createView(type, parent, cb);
  21. },
  22. createView(type, parent, cb) {
  23. if (this.createIndex >= this.datas.length) {
  24. return;
  25. }
  26. let data = this.datas[this.createIndex]
  27. let self = this
  28. this.rootNode.createComponent(type, parent, data, function(node, status) {
  29. if (status != 'ok') {
  30. return
  31. }
  32. let index = self.createIndex
  33. self.createIndex += 1;
  34. self.cells.push(node);
  35. self.createView(type, parent, cb);
  36. if (cb) {
  37. cb(node, index, data);
  38. }
  39. })
  40. },
  41. })