Files
SuperScrollView_2.X/assets/scripts/baseMain.ts

43 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-01-13 09:27:08 +08:00
import SuperLayout from '../core/super-layout';
import BaseItem from './baseItem';
const { ccclass, property } = cc._decorator;
@ccclass
export default class BaseMain extends cc.Component {
@property(SuperLayout) layout: SuperLayout = null
@property(cc.EditBox) input: cc.EditBox = null
protected datas: any[] = []
toHeader() {
this.layout.scrollToHeader(1)
}
toFooter() {
this.layout.scrollToFooter(1)
}
toIndex() {
var index = Number(this.input.string)
if (isNaN(index)) return
this.layout.scrollToIndex(index, 1)
}
toBack() {
cc.director.loadScene("main")
}
onRefreshEvent(item: cc.Node, index: number) {
item.getComponent(BaseItem).show(this.datas[index], index, this.onClickItem.bind(this))
}
onClickItem(index: number) {
this.datas.splice(index, 1)
this.layout.total(this.datas.length)
}
addItem(event: any, args: any) {
let count = Number(args)
if (isNaN(count)) return
for (let i = 0; i < count; i++) {
this.datas.push({ message: this.datas.length })
}
this.layout.total(this.datas.length)
}
}