将onLoad侦听器添加到Sencha触摸列表

CoolMonster

我想在数据加载后列表 执行选择操作,因为基于接收到的数据,我必须在该列表中选择一个单元格,并且还需要基于此更新详细视图。

    Ext.define('WaxiApp.view.ProductViews.ProductList', {
    extend: 'Ext.Container',
    alias: "widget.ProductList",
    requires: [
                   'Ext.Img',
    ],
    config: {
        layout: Ext.os.deviceType == 'Phone' ? 'fit' : {
            type: 'hbox',
            pack:'strech'
        },
        cls: 'product-list',
        items: [{
            xtype: 'list',
            id:'product-list-view',
            width: '100%',
            height:'100%',
            store: 'ProductsList',
            infinite: true,
            plugins: 'sortablelist',
            itemCls: 'productList',
            itemId:"product-item",
            itemTpl: new Ext.XTemplate(
                '<div class="list-content-div ',
      '<tpl if="this.needSortable(isNeedInventry)">',
            Ext.baseCSSPrefix + 'list-sortablehandle',

        '</tpl>',
         '">',
         '<b>{UpcCode} {Name}</b>',
        '<tpl if="isActive">',
            '</div>',
        '</tpl>',
            {
                // XTemplate configuration:
                compiled: true,
                // member functions:
                needSortable: function (isneedInventry) {
                    return !isneedInventry;
                },
            }),
            masked: { xtype: 'loadmask',message: 'loading' },
            onLoad: function (store) {
                this.unmask();
                console.log('list loaded');
                this.fireEvent("productListLoadedCommand", this,store);
            },

        }
        ],
        listeners: [
                {
                    delegate: "#product-list-view",
                    event: "itemtap",
                    fn: function (list, index, target, record) {
                        console.log(index);
                        console.log('list selection command fired');
                        this.fireEvent("productListSelectedCommand", this,index,record);
                    }
                }

        ],
        style: 'background-image: -webkit-gradient(linear, left top, right bottom, color-stop(0, #FDFDFD), color-stop(1, #DBDBDB));background-image: linear-gradient(to bottom right, #FDFDFD 0%, #DBDBDB 100%);'
    }//End of config

});//End of Define

在此实际视图上方,我用来显示列表。我的问题是我尝试了onLoad()方法,但是我想在Controller中做所有事情使其更加清晰。

如您所见,我的itemTap事件已通过触发事件在Controller中处理。但是对于load事件而言,这是不起作用的

CoolMonster

我找到了确切的解决方案来处理这种情况,并发布了自己的解决方案。

ProductList.js

Ext.define('WaxiApp.view.ProductViews.ProductList', {
extend: 'Ext.Container',
alias: "widget.ProductList",
requires: [
               'Ext.Img',
],
initialize: function () {

    this.add([
        {
            xtype: 'list',
            id: 'product-list-view',
            store: 'ProductsList',
            masked: { xtype: 'loadmask', message: 'loading' },
            //onLoad is not a listener it's private sencha touch method used to unmask the screen after the store loaded
            onLoad: function (store) {
                this.unmask();//I manually unmask, because I override this method to do additional task.
                console.log('list loaded');
                this.fireEvent("productListLoadedCommand", this, store);
            }
            ,
            //Painted is event so added it to listener, I saw fee document state that, add event like Painted and show should to added to the
            //Component itslef is best practice. 
            listeners: {
                order: 'after',
                painted: function () {
                    console.log("Painted Event");
                    this.fireEvent("ProductListPaintedCommand", this);
                },
                scope: this
                 //This is also very important, because if we using this in card layout
                 //and changing the active view in layout cause this event to failed, so
                 //setting scope to this will help to receive the defined view instead of this list component.
            }

        }]);
},

config: {
    listeners: [
            {
                delegate: "#product-list-view",
                event: "itemtap",
                fn: function (list, index, target, record) {
                    console.log(index);
                    console.log('list selection command fired');
                    this.fireEvent("productListSelectedCommand", this, index, record);
                }
            }
    ],

    }//End of config

});//End of Define

ProductViewController.js

/// <reference path="../../touch/sencha-touch-all-debug.js" />


Ext.define("WaxiApp.controller.ProductsViewController", {

    extend: "Ext.app.Controller",
    listStoreNeedLoad:true,
    config: {
        refs: {
            ProductContainer: "ProductList",
            ProductList: "#product-list-view",
            ProductDetailView:"ProductDetail"
        },
        control: {
            ProductContainer:{
                productListSelectedCommand: "onProductListSelected",
                ProductListPaintedCommand: "onProductListPainted"
            },
            ProductList:{
                productListLoadedCommand: "onProductListLoaded"        
            }

        }//End of control

    },//End of config
    // Transitions
    getstore:function(){
        return Ext.ComponentQuery.query('#product-list-view')[0].getStore();
    },
    onProductListPainted:function(list)
    {
        //Check for if need to load store because painted event called every time your view is painted on screen
        if (this.listStoreNeedLoad) {
            var store = this.getstore();
            this.getstore().load();
        }
    },
    onProductListLoaded:function(list,store)
    {
        this.listStoreNeedLoad = false;
        var index = 0;
        //Iterate through record and set my select Index
        store.each(function(record,recordid){
            console.info(record.get("isNeedInventry"));
            if (record.get("isNeedInventry")) {
                return false;
            }
            index++;
        });

        console.log('list load event fired');
        if(Ext.os.deviceType.toLowerCase()!='phone')
        {
            this.setRecord(store.getAt(index));
            list.select(index);
        }

    }

})//End of define

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

将onLoad侦听器添加到Sencha触摸列表

来自分类Dev

将侦听器添加到将仅称为onload的JPanel中

来自分类Dev

如何将事件侦听器添加到动态创建的HTML列表元素?

来自分类Dev

将SSL侦听器添加到UnboundID

来自分类Dev

Linux将侦听器添加到日志文件

来自分类Dev

将事件侦听器添加到if语句

来自分类Dev

将侦听器添加到Google Map

来自分类Dev

JMapViewer将鼠标侦听器添加到MapMarkerDot

来自分类Dev

将拖动事件侦听器添加到iframe

来自分类Dev

使用Lambda将侦听器添加到ObjectAnimator

来自分类Dev

将setTimeout添加到事件侦听器

来自分类Dev

将setTimeout添加到事件侦听器

来自分类Dev

将setTimeout添加到事件侦听器

来自分类Dev

将setTimeout添加到事件侦听器

来自分类Dev

将事件侦听器添加到绘制的对象

来自分类Dev

将侦听器添加到类或元素

来自分类Dev

如何将侦听器添加到表?

来自分类Dev

动态将动作侦听器添加到按钮

来自分类Dev

将动作侦听器添加到JPanel

来自分类Dev

尝试将事件侦听器添加到JTextField

来自分类Dev

JFXtras将侦听器添加到拖动约会

来自分类Dev

将侦听器添加到TableViewer编辑列

来自分类Dev

将侦听器添加到JPanel

来自分类Dev

将“this”添加到事件侦听器?

来自分类Dev

将事件侦听器添加到由事件侦听器添加的表单元素

来自分类Dev

如何将侦听器添加到使用CheckBoxListCell的列表视图中的复选框

来自分类Dev

在Vaadin的列表可编辑模式下将侦听器添加到所有单元格

来自分类Dev

在Vaadin的列表可编辑模式下将侦听器添加到所有单元格

来自分类Dev

动作3-将鼠标侦听器添加到鼠标侦听器中吗?

Related 相关文章

热门标签

归档