发一个封装了Listview组建的Demo

在官方demo基础上修改的列表,用法类似以前的tableview,方便开发!

拖一个scrollview,给它增加脚本组建AgListView;然后在其content节点里面拖一个按钮,并命名为item;大厅脚本就可以如下操作:

var AGListView = require(“AgListView”);
cc.Class({
extends: cc.Component,
properties: {},

onLoad: function () {
    this._scrollViewList = cc.find("Canvas/scrollViewList").getComponent(AGListView);
    this._scrollViewList.setCount(50);
    this._scrollViewList.setSpace(2);
    this._scrollViewList.setCallback(function(item,index){
        item.getChildByName('labelName').getComponent(cc.Label).string = '房间'+index;
        item.getChildByName('labelCount').getComponent(cc.Label).string = '20/100';
        item.getChildByName('labelTime').getComponent(cc.Label).string = '2分钟35秒';
        item.off('touchend');
        item.on('touchend', function () {
            cc.log("Item " + index + ' clicked');
        }, this);
    });
    this._scrollViewList.reload();
},

});

ListViewDemo.zip (219.2 KB)

1赞