PVCtrl.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. var jobData = require('../data/job');
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. pageview: cc.PageView,
  6. jobItem: cc.Node,
  7. },
  8. bind(currentJobId) {
  9. this.pageview.removeAllPages();
  10. this.jobList = [];
  11. if (currentJobId) {
  12. for (var i = 0; i < jobData.length; i++) {
  13. if (jobData[i].id == currentJobId) {
  14. } else {
  15. this.jobList.push(jobData[i]);
  16. }
  17. }
  18. }else{
  19. this.jobList = jobData;
  20. }
  21. for (var i = 0; i < this.jobList.length; i++) {
  22. let item = cc.instantiate(this.jobItem);
  23. item.active = true;
  24. item.position = new cc.p(0, 0);
  25. item.getComponent('JobItem').bind(this.jobList[i]);
  26. this.pageview.addPage(item);
  27. }
  28. ///动态添加item的时候必须加这两行代码,刷新PageView的各种数值参数,让界面正常显示
  29. this.pageview.sizeMode = cc.PageView.SizeMode.Free;
  30. this.pageview._updatePageView();
  31. },
  32. bindJobList(jobList) {
  33. this.pageview.removeAllPages();
  34. this.jobList = jobList;
  35. for (var i = 0; i < this.jobList.length; i++) {
  36. let item = cc.instantiate(this.jobItem);
  37. item.active = true;
  38. item.position = new cc.p(0, 0);
  39. item.getComponent('JobItem').bind(this.jobList[i]);
  40. this.pageview.addPage(item);
  41. }
  42. ///动态添加item的时候必须加这两行代码,刷新PageView的各种数值参数,让界面正常显示
  43. this.pageview.sizeMode = cc.PageView.SizeMode.Free;
  44. this.pageview._updatePageView();
  45. },
  46. getCurrentJob() {
  47. return this.jobList[this.pageview.getCurrentPageIndex()];
  48. },
  49. // update (dt) {},
  50. });