PVCtrl.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. artistIconSprite: cc.Sprite,
  9. artistLabel: cc.Label,
  10. jobIconFrames: [cc.SpriteFrame],
  11. },
  12. bind(currentJobId, gender) {
  13. this.gender = gender;
  14. this.pageview.removeAllPages();
  15. this.jobList = [];
  16. if (currentJobId) {
  17. for (var i = 0; i < jobData.length; i++) {
  18. if (jobData[i].id == currentJobId) {
  19. } else {
  20. this.jobList.push(jobData[i]);
  21. }
  22. }
  23. } else {
  24. this.jobList = jobData;
  25. }
  26. for (var i = 0; i < this.jobList.length; i++) {
  27. let item = cc.instantiate(this.jobItem);
  28. item.active = true;
  29. item.position = new cc.p(0, 0);
  30. item.getComponent('JobItem').bind(this.jobList[i]);
  31. this.pageview.addPage(item);
  32. }
  33. ///动态添加item的时候必须加这两行代码,刷新PageView的各种数值参数,让界面正常显示
  34. this.pageview.sizeMode = cc.PageView.SizeMode.Free;
  35. this.pageview._updatePageView();
  36. },
  37. bindJobList(jobList) {
  38. this.pageview.removeAllPages();
  39. this.jobList = jobList;
  40. for (var i = 0; i < this.jobList.length; i++) {
  41. let item = cc.instantiate(this.jobItem);
  42. item.active = true;
  43. item.position = new cc.p(0, 0);
  44. item.getComponent('JobItem').bind(this.jobList[i], this.gender);
  45. this.pageview.addPage(item);
  46. }
  47. ///动态添加item的时候必须加这两行代码,刷新PageView的各种数值参数,让界面正常显示
  48. this.pageview.sizeMode = cc.PageView.SizeMode.Free;
  49. this.pageview._updatePageView();
  50. },
  51. bindSelectedJobText() {
  52. let jobInfo = this.jobList[this.pageview.getCurrentPageIndex()];
  53. this.artistIconSprite.spriteFrame = this.jobIconFrames[jobInfo.id - 1];
  54. this.artistLabel.string = jobInfo.name;
  55. this.summaryLabel.string = jobInfo.msg;
  56. },
  57. getSelectedJob() {
  58. return this.jobList[this.pageview.getCurrentPageIndex()];
  59. },
  60. // update (dt) {},
  61. });