PVCtrl.js 2.2 KB

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