开发者

Sencha Touch List Append New Results from Store Load

开发者 https://www.devze.com 2023-03-30 06:37 出处:网络
I\'ve got a simple List, which loads data from a JSON Store. I\'ve got the paging solved server-side, so in order to get a new page I change the proxy of the store and set page parameter to +1(new pag

I've got a simple List, which loads data from a JSON Store. I've got the paging solved server-side, so in order to get a new page I change the proxy of the store and set page parameter to +1(new page), load the store and the list shows just new results from the new page. Is it possible to make the list append new results after the store load? So that when I load the store with new data I want the list to keep old data and add new ones. If it's needed I can show it in code but it's pretty much self-describing. Thanks.

//edit

Currently my store looks like this:

realio.stores.results = new Ext.data.Store({
    model: "realio.models.Results",
    proxy: {
        type: 'ajax',
        url: 'http://site.com/json_list2.php?a=l&zp=1&u='+settings["ulica"]+'&c0='+settings["cena0"]+'&c1='+settings["cena1"]+'&p0='+settings["plocha0"]+'0&p1='+settings["plocha1"]+'&cm20='+settings["cenam20"]+'&cm21='+settings["cenam21"]+'&pg=0&s=Datumu&t='+settings["typ"]+'&age='+settings["stari"]+'&pod='+settings["podlazi"]+'&lat='+settings["lat"]+'&lng='+settings["lng"]+'&pp='+settings["pp"]+'&tp0='+settings["typ0"]+'&tp1='+settings["typ1"],
        reader: {
            type: 'json',
            root: 'markers'
        }
    },
    sorters: [
        {
            property: 'id',
            direction: 'ASC'
        }
    ]
});

and my model like this

realio.models.Results = Ext.regModel("realio.models.Results", {
    fields: [
        {name: "titul", type: "string"},
        {name: "vlast", type: "string"},
        {name: "typb", type: "string"},
        ...
    ]
});

list:

xtype: 'list',
store: realio.stores.results,
flex: 1,
disableSelection: true,
scroll: 'vertical',
itemTpl: itemTemplate,
onItemDisclosure: function (record) {
    Ext.dispatch({
        controller: realio.controllers.detail,
        action: 'load',
        detail: record
    });
},
listeners: {
    'itemtap': function(t, i, it, e) {
        Ext.dispatch({
            controller: realio.controllers.detail,
            action: 'load',
            detail: t.store.getAt(i)
        });
     }
},
plugins: [
    {
        ptype: 'listpaging',
        autoPaging: false
    }, 
    {
        pty开发者_StackOverflow社区pe: 'pullrefresh'
    }
]

I've got the paging solved server-side -> when i set &pg = x in proxy url, i go to the page x, so I don't know how I would get it to run with those store pages. Even if I tried setting stores pagesize to for example 2 it would show all results anyway so I thought it doesn't work...


From my experience I would do store.loadData(data,true); true to append the data to the data that is already in the list.


There is a plugin that ships with Sencha Touch 1.1 called ListPagingPlugin which lets you add a 'load more' button to the end of a list that'll fetch the next page and append the data. There's an example (also included) that you can find in /examples/pullrefresh (it's bundled with the pull to refresh plugin in a single example).

The example didn't work for me because I think Twitter changed their API so that if an invalid page parameter is sent it doesn't default to page 1 rather it tells you -some- parameter is invalid. In order to make the example work I had to edit line 44 of /examples/pullrefresh/src/TwitterProxy.js from page: operation.page to page: operation.page || 1

If you have any questions about the plugin specifically after you start using it we can cross that bridge when you get there =D

0

精彩评论

暂无评论...
验证码 换一张
取 消