12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- var jobData = require('../data/job');
- cc.Class({
- extends: cc.Component,
- properties: {
- pageview: cc.PageView,
- jobItem: cc.Node,
- },
- 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();
- },
- getCurrentJob() {
- return this.jobList[this.pageview.getCurrentPageIndex()];
- },
- // update (dt) {},
- });
|