Source: control/ListView.js

/**
 * Created by seeker910 on 2017/6/29.
 * 
 * dataSource类型支持Rsd.data.Store ,Rsd.data.Service
 * 可绑定服务端数据和本地数据源
 */
Rsd.define('Rsd.control.ListView', {
    extend: 'Rsd.control.List',
    requires: [
        'Rsd.data.Store',
        'Rsd.form.Text',
        'Rsd.form.ComboBox' 
    ],
    xtype:'list-view',
    cls: 'x-list-view',
    /**   
     * */ 
    constructor: function ListView(config) {
        config = config || {};
       
        this.apply(config);

    },
    /**
     @public
     @description 加载dataSource到空间上;
     @description 1、dataSource 是数组对象,直接将数组元素作为congfig 传给item 控件
     @description 2、dataSource 是Rsd.data.Store,将查询返回的对象作为congfig.data的值 传给item 控件
     @description 3、dataSource 是Rsd.data.Service,将查询返回的对象作为congfig.data的值 传给item 控件
     * */
    loadData:function loadData(args,callback) {

        //this.log(this.dataSource);
        //数据源 为数组
        if(args instanceof Array)
        {
            //listview对象load方法
            this.callParent(args,callback); 
            return;
        } 
        if(this.dataSource instanceof Array)
        {
            //listview对象load方法
            this.callParent(this.dataSource,callback); 
            return;
        }

        if(this.dataSource == null) 
        {
            Rsd.log('dataSource value is null for Control ListView(id:' +this.id+ ').');
            Rsd.callFunction(this,callback,null);
            return;
        }
        var me = this;
        //debugger;
        //数据源 为Rsd.data.Store
        if(this.dataSource instanceof Rsd.data.Store) {

            var _args = Rsd.apply({}, args);

            this.dataSource.load(_args,function loadData(data){
                //console.log(data);
                if (data != null) {
                    //Rsd.debug("Rsd.control.ListView.loadData()");
                    if(!data.hasOwnProperty('success'))
                    {
                        console.error('返回数据格式不正确,未找到[success]属性。');
                    }
                    if (data.success) {

                        var _data = data.data;

                        me.indexStart = _data.pagesize * _data.pageindex  + 1;
                         
                        me.callParent(_data.rows,callback);

                    }
                    else
                    {
                        Rsd.alert('加载数据出现错误 ', data.msg|| '未知错误');
                    }
                } 
                else
                {
                    Rsd.callFunction(me,callback,[data]);
                }
            });
            return;
        }

        //数据源为 Rsd.data.Service
        if(this.dataSource instanceof Rsd.data.Service) {
            var _args = Rsd.apply({}, args);

            this.dataSource.request(_args,function loadData(data){
                if (data != null) {
                    Rsd.debug("Rsd.control.ListView.loadData()");
                    if(!data.hasOwnProperty('success'))
                    {
                        throw new Error('返回数据格式不正确,未找到[success]属性。');
                    }
                    if (data.success) {
                        var _data = data.data||data;
                     
                        me.indexStart = _data.pagesize * _data.pageindex  + 1;
                      
                        var _rows = _data[me.dataSource.listName||'rows'];
                       
                        me.callParent(_rows,callback);

                    }
                    else
                    {
                        Rsd.alert('加载数据出现错误 ', data.msg|| '未知错误');
                    }
                }
                else
                {
                    Rsd.callFunction(me,callback,[data]);
                }
               
            });
            return;
        }
        
        Rsd.callFunction(me,callback,[this.dataSource]);
        Rsd.error('ListView属性dataSource不是有效值:' , this.dataSource );
    }
});