1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- var jobData = require('../data/job');
- cc.Class({
- extends: cc.Component,
- properties: {
- pageview: cc.PageView,
- jobItem: cc.Node,
- summaryLabel: cc.Label,
- titleText: cc.RichText,
- },
- bind(currentJobId) {
- this.pageview.removeAllPages();
- this.jobList = [];
- if (currentJobId) {
- for (var i = 0; i < jobData.length; i++) {
- if (jobData[i].id == currentJobId) {
- } else {
- this.jobList.push(jobData[i]);
- }
- }
- } else {
- this.jobList = jobData;
- }
- for (var i = 0; i < this.jobList.length; i++) {
- let item = cc.instantiate(this.jobItem);
- item.active = true;
- item.position = new cc.p(0, 0);
- item.getComponent('JobItem').bind(this.jobList[i]);
- this.pageview.addPage(item);
- }
- ///动态添加item的时候必须加这两行代码,刷新PageView的各种数值参数,让界面正常显示
- this.pageview.sizeMode = cc.PageView.SizeMode.Free;
- this.pageview._updatePageView();
- },
- bindJobList(jobList) {
- this.pageview.removeAllPages();
- this.jobList = jobList;
- for (var i = 0; i < this.jobList.length; i++) {
- let item = cc.instantiate(this.jobItem);
- item.active = true;
- item.position = new cc.p(0, 0);
- item.getComponent('JobItem').bind(this.jobList[i]);
- this.pageview.addPage(item);
- }
- ///动态添加item的时候必须加这两行代码,刷新PageView的各种数值参数,让界面正常显示
- this.pageview.sizeMode = cc.PageView.SizeMode.Free;
- this.pageview._updatePageView();
- },
- bindSelectedJobText() {
- let jobInfo = this.jobList[this.pageview.getCurrentPageIndex()];
- let picId = 50000 + jobInfo.id;
- this.titleText.string = `<img src='${picId}' /> <outline color=#584A47 width=3><b>${jobInfo.name}</b></outline>`;
- this.summaryLabel.string = jobInfo.msg;
- },
- getSelectedJob() {
- return this.jobList[this.pageview.getCurrentPageIndex()];
- },
- // update (dt) {},
- });
|