简体   繁体   English

Sencha Touch-如何启用无限滚动

[英]Sencha Touch - How to enable Infinite Scroll

Looking in the Docs for Sencha Touch there seems to be an option on the List widget that allows for setting "infinite" which enables infinite scroll. 在Sencha Touch的文档中查找,似乎在“列表”小部件上有一个选项可以设置“无限”,从而启用无限滚动。

Docs: https://docs.sencha.com/touch/2.3.1/#!/api/Ext.dataview.List-cfg-infinite 文件: https//docs.sencha.com/touch/2.3.1/#!/api/Ext.dataview.List-cfg-infinite

I am hoping this will resolve some issues that I have with performance with very large lists on portable devices. 我希望这可以解决便携式设备上的大量清单所带来的性能问题。

Important Note: This is for an offline mobile app. 重要说明:这是针对离线移动应用的。 As in the fiddle. 如小提琴。 The store already contains all of the data. 该存储区已包含所有数据。

I tried enabling it on a large list but all it does is hide the data. 我试图在一个很大的列表上启用它,但是它所做的就是隐藏数据。

{
    xtype: 'list',
    store: 'contactStore',
    flex: 1,
    itemTpl: '<table><tr><td class="contact"><strong>{firstname}</strong> {lastname}</td></tr><tr><td>{companyname}</td></tr><tr><td>{address}, {city}, {province}, {postal}</td></tr><tr><td>{phone1}, {phone2}, {email}</td></tr><tr><td>{web}</td></tr></table>',

    infinite: true /* Setting this to true hides the list */
}

What am I missing? 我想念什么? I have included a jsFiddle. 我包括一个jsFiddle。

http://jsfiddle.net/AnthonyV/bba58zfr/ http://jsfiddle.net/AnthonyV/bba58zfr/

The issue here isn't anything about the data being loaded like the other answers. 此处的问题与其他答案一样,都与加载数据无关。 You have said the data is being loaded into the store just fine as when you don't have infinite set to true you can see the data. 您已经说过将数据加载到存储中就好了,因为当您没有将infinite设置为true您就可以看到数据。

First, let's discuss what the infinite config does. 首先,让我们讨论infinite配置的作用。 As Anand Gupta explained, the infinite config will only render the number of list items that can fit on the screen (plus some as a buffer for scrolling). 正如Anand Gupta所解释的那样, infinite配置将仅呈现可以在屏幕上容纳的列表项的数量(加上一些作为滚动缓冲区)。 If you don't have it set to true then the list will render all items and not manage a visible range. 如果您未将其设置为true则该列表将呈现所有项目并且不管理可见范围。 With all items rendered, the list can support auto sizing. 渲染所有项目后,列表可以支持自动调整大小。 However, when infinite is set to true , the list needs to know what size it has in order to calculate the number of visible rows it can render. 但是,当infinite设置为true ,列表需要知道其大小才能计算其可以呈现的可见行数。

This is where the issue happens, the list doesn't have a full size set to it. 这是发生问题的地方,列表没有设置完整大小。 You have the list nested in a container and that container uses vbox layout: 您将列表嵌套在容器中,并且该容器使用vbox布局:

config: {
    title: 'Big List Issue',
    fullscreen: true,
    items: [{
        xtype: 'container',
        layout: 'vbox',
        title: 'Big List',
        items: [{
            xtype: 'list',
            store: 'contactStore',
            id: 'simpleList',
            flex: 1,
            itemTpl: '<table><tr><td class="contact"><strong>{firstname}</strong> {lastname}</td></tr><tr><td>{companyname}</td></tr><tr><td>{address}, {city}, {province}, {postal}</td></tr><tr><td>{phone1}, {phone2}, {email}</td></tr><tr><td>{web}</td></tr></table>',
            striped: true,
            infinite: false
        }]
    }]
}

This is technically overnesting. 从技术上讲这太过分了。 Overnesting is when you have nested a component within a container that doesn't need to be nested within the container. 过度嵌套是指您在容器中嵌套了不需要嵌套在容器中的组件时。 This is an unnested version of your code that should work as you want: 这是您的代码的非嵌套版本,可以根据需要运行:

config: {
    title: 'Big List Issue',
    fullscreen: true,
    items: [{
        xtype: 'list',
        title: 'Big List',
        store: 'contactStore',
        id: 'simpleList',
        itemTpl: '<table><tr><td class="contact"><strong>{firstname}</strong> {lastname}</td></tr><tr><td>{companyname}</td></tr><tr><td>{address}, {city}, {province}, {postal}</td></tr><tr><td>{phone1}, {phone2}, {email}</td></tr><tr><td>{web}</td></tr></table>',
        striped: true,
        infinite: true,
        variableHeights: true
    }]
}

What I did here is remove the container and had the list as a direct child of your MyApp.view.MyIssue navigation view. 我在这里所做的是删除容器,并将该列表作为MyApp.view.MyIssue导航视图的直接子MyApp.view.MyIssue The navigation view uses card layout which will give each direct child 100% height and width and therefore allowing the list to calculate the number of rows it can render with infinite set to true . 导航视图使用卡片布局,该布局将为每个直接子对象提供100%的高度和宽度,因此允许列表计算将infinite设置为true时可以呈现的行数。 Here is a Sencha Fiddle to show this unnested list in action: https://fiddle.sencha.com/#fiddle/11v1 这是一个Sencha小提琴,用于显示此未嵌套的列表: https ://fiddle.sencha.com/#fiddle/11v1

The other way, if you REALLY wanted the list to be nested in that container (the more you nest, the bigger the DOM since you have more components created and the bigger the DOM, the slower your app may respond) then you can give the container's vbox layout the align config: 换句话说,如果您真的希望列表嵌套在该容器中(嵌套的越多,则DOM越大,因为创建了更多的组件,而DOM越大,则应用程序响应速度越慢),则可以给容器的vbox布局align配置:

config: {
    title: 'Big List Issue',
    fullscreen: true,
    items: [{
        xtype: 'container',
        layout: {
            type: 'vbox',
            align: 'stretch'
        },
        title: 'Big List',
        items: [{
            xtype: 'list',
            store: 'contactStore',
            id: 'simpleList',
            flex: 1,
            itemTpl: '<table><tr><td class="contact"><strong>{firstname}</strong> {lastname}</td></tr><tr><td>{companyname}</td></tr><tr><td>{address}, {city}, {province}, {postal}</td></tr><tr><td>{phone1}, {phone2}, {email}</td></tr><tr><td>{web}</td></tr></table>',
            striped: true,
            infinite: true
        }]
    }]
}

In the unnested list example, I also use the variableHeights config on the list. 在未嵌套的列表示例中,我还使用列表上的variableHeights配置。 This allows the list items to be properly heighted. 这样可以正确列出列表项。 Run the fiddle with it commented out to see the difference it makes. 用小提琴将其注释掉,以查看其不同之处。

First you need to understand that infinite: true helps in improving list performance. 首先,您需要了解infinite: true有助于提高列表性能。 It helps rendering only that chunk of list data which is the current page, rest are not rendered. 它有助于仅呈现当前页面的那部分列表数据,其余的则不呈现。 So, 所以,

  1. For pagination, you backend should support that like it should have parameter like limit , start , pageSize etc. 对于分页,您的后端应支持它应该具有诸如limitstartpageSize等参数。

  2. For implementing pagination, your store should have these configs like pageSize , buffered etc. 为了实现分页,您的store应具有以下配置,如pageSizebuffered等。

Hence if your backend support and you have implemented pagination . 因此,如果您的后端支持并且已实现分页 Then you can enjoy the benefit of infinite: true and get extreme sencha touch list performance. 然后,您可以享受infinite: true的优势infinite: true并获得极端的sencha触摸列表性能。

You can go with this. 你可以这样。 Add this plugin, It handles automatically infinite scrolling. 添加此插件,它将自动处理无限滚动。

http://docs.sencha.com/touch/2.4/2.4.0-apidocs/#!/api/Ext.plugin.ListPaging http://docs.sencha.com/touch/2.4/2.4.0-apidocs/#!/api/Ext.plugin.ListPaging

For offline 离线

You can implement an idea. 您可以实施一个想法。 Create 2 store one is fully loaded and second will load only with some page size suppose 10. You will use second store in your grid and implement list paging plugin, also pass here second store. 创建2个存储,其中一个是完全加载的,第二个将仅以某个页面大小加载。假设10。您将在网格中使用第二个存储并实现列表分页插件,也将第二个存储传递到此处。 You can take help with this fiddle example. 您可以在这个小提琴示例中寻求帮助。 (this example is in Ext jS 5 but logic will be same) (此示例在Ext jS 5中,但逻辑相同)

https://fiddle.sencha.com/#fiddle/pim https://fiddle.sencha.com/#fiddle/pim

Please try this one and let us know. 请尝试这个,让我们知道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM