const ListAdapter = require('../friendlist/ListViewAdapter'); cc.Class({ extends: cc.Component, properties: { scrollView: cc.ScrollView, content: cc.Node, tipLabel: cc.Label, item: cc.Prefab, itemScriptName: 'RankItem', myItem: cc.Node, }, onLoad() { this.listAdapter = new ListAdapter(this.scrollView); this.setLoading(); }, bindData(data) { this.myItem.getComponent(this.itemScriptName)._bindData(data.me); if (data.ranks) { this.listAdapter.updateItems(data.ranks, this.item, this.itemScriptName); // data.ranks.forEach(dataItem => { // let child = cc.instantiate(this.item); // this.content.addChild(child); // child.getComponent(this.itemScriptName).updateItem(dataItem, 0); // }); this.content.active = true; this.tipLabel.node.active = false; } else { this.content.active = false; this.tipLabel.node.active = true; this.tipLabel.string = "暂无数据"; } }, networkError(error) { console.log(error); this.tipLabel.node.active = true; this.tipLabel.string = '网络错误'; this.content.active = false; }, setLoading() { this.content.active = false; this.tipLabel.node.active = true; this.tipLabel.string = "加载中..."; }, update(dt) { // this.listAdapter.update(dt); }, onScrollEvent() { if (this.listAdapter) { this.listAdapter.update(); } }, });