1. #1
    Sencha User
    Join Date
    Oct 2012
    Posts
    18
    Answers
    1
    Vote Rating
    0
    Shaci is on a distinguished road

      0  

    Default Unanswered: nested list with ajax and proxy

    Unanswered: nested list with ajax and proxy


    Hi to all, i have a little issue with nested list and proxy.

    I created simple working example of nested list.
    Here is.

    app.js
    Code:
    Ext.application({
        name: 'MyApp',
        models: ['ListItem'],
        stores: ['ListStore'],
        views: ['NestedView'],
        launch: function () {
            
            var nestedList = { xtype: 'nestedview', store: Ext.getStore("ListStore"), flex: 1 }
    
    
            Ext.Viewport.add({
                layout: 'hbox',
                items: [
                nestedList]
            });
        } // launch
    }); // application()
    app/view/NestedView.js

    Code:
    Ext.define('MyApp.view.NestedView', {
      extend: 'Ext.dataview.NestedList',
      alias: 'widget.nestedview',
      getItemTextTpl: function(recordnode) {  return '<div><strong>name: {name} balance: {balance}</strong></div>'; }
    })
    app/model/ListItem.js

    Code:
    Ext.define('MyApp.model.ListItem', {
      extend: 'Ext.data.Model',
      config: {
        fields: [{name: 'name', type: 'string'}, {name: 'balance', type: 'int'}]
      }
    });
    and store:

    app/store/ListStore.js

    Code:
    Ext.define('MyApp.store.ListStore', {
        extend: "Ext.data.TreeStore",
        config: {
          model: 'MyApp.model.ListItem',
          defaultRootProperty: 'items',
          root: {
              items: [{"_id":"5072913b43749c1824000005","account_category":"cat1","balance":60000,"created_at":"2012-10-08T12:39:23+04:00","currency":"rub","name":"VISA","updated_at":"2012-10-08T13:36:35+04:00"},{"_id":"50754f9d43749c0dd8000003","account_category":"cat1","balance":60000,"created_at":"2012-10-10T14:36:13+04:00","currency":"rub","name":"VTB","updated_at":"2012-10-12T22:42:57+04:00"}]
              
          }
        //  proxy: {
        //      type: 'ajax',
        //      url : 'accounts.json',
        //      reader: { type: 'json'}
        //  }
        }
    });
    When i use hardcode items all ok, but when i use proxy and such ListStore.js file:

    Code:
    Ext.define('MyApp.store.ListStore', {
        extend: "Ext.data.TreeStore",
        config: {
          model: 'MyApp.model.ListItem',      
          proxy: {
              type: 'ajax',
              url : 'accounts.json',
              reader: { type: 'json'}
          }
        }
    });
    with accounts.json file:

    Code:
    [{"_id":"5072913b43749c1824000005","account_category":"cat1","balance":60000,"created_at":"2012-10-08T12:39:23+04:00","currency":"rub","name":"VISA","updated_at":"2012-10-08T13:36:35+04:00"},{"_id":"50754f9d43749c0dd8000003","account_category":"cat1","balance":60000,"created_at":"2012-10-10T14:36:13+04:00","currency":"rub","name":"VTB","updated_at":"2012-10-12T22:42:57+04:00"}]
    I have some bugs (i can tap on each item any number of times, and i get infinite scrolling )

    Does anyone has suggestions what i doing wrong?

  2. #2
    Sencha User
    Join Date
    Apr 2010
    Location
    China
    Posts
    227
    Answers
    64
    Vote Rating
    20
    haduki will become famous soon enough haduki will become famous soon enough

      0  

    Default


    because:
    Code:
    defaultRootProperty: 'items',
    your response have to:
    Code:
    {    
        items:[
            {},{}
        ]
    }
    I write English by translator.

  3. #3
    Sencha User
    Join Date
    Oct 2012
    Posts
    18
    Answers
    1
    Vote Rating
    0
    Shaci is on a distinguished road

      0  

    Default


    Thanks a lot, but i dont use
    Code:
    defaultRootProperty: 'items'
    in second variant of ListStore.js

    I write another variant now:

    accounts.js as you say:

    Code:
    {
        "items":[             {"_id":"5072913b43749c1824000005","account_category":"cat1","balance":60000,"created_at":"2012-10-08T12:39:23+04:00","currency":"rub","name":"VISA","updated_at":"2012-10-08T13:36:35+04:00"},             {"_id":"50754f9d43749c0dd8000003","account_category":"cat1","balance":60000,"created_at":"2012-10-10T14:36:13+04:00","currency":"rub","name":"VTB","updated_at":"2012-10-12T22:42:57+04:00"}
                ]
    }

    and ListStore.js with rootProperty

    Code:
    Ext.define('MyApp.store.ListStore', {
        extend: "Ext.data.TreeStore",
        
        config: {
          model: 'MyApp.model.ListItem',      
          proxy: {
              type: 'ajax',
              url : 'accounts.json',
              reader: {
                type: 'json',
                rootProperty: 'items'
            }
          }
        }
    });
    it works, but bugs still here

  4. #4
    Sencha User
    Join Date
    Apr 2010
    Location
    China
    Posts
    227
    Answers
    64
    Vote Rating
    20
    haduki will become famous soon enough haduki will become famous soon enough

      1  

    Default


    have you tried
    Code:
    Ext.define('MyApp.store.ListStore', {
        extend: "Ext.data.TreeStore",
            config: {
               model: 'MyApp.model.ListItem',      
               defaultRootProperty: 'items',
               proxy: {
                 type: 'ajax',
                 url : 'accounts.json',
                 reader: {
                   type: 'json'
                 }
               }
        }
    });
    though you did not specify 'defaultRootProperty',it dose not mean 'defaultRootProperty' is null.

    if you dislike 'defaultRootProperty',your response should be:(also don't set your reader's rootProperty config)
    Code:
    {    "children":[             {"_id":"5072913b43749c1824000005","account_category":"cat1","balance":60000,"created_at":"2012-10-08T12:39:23+04:00","currency":"rub","name":"VISA","updated_at":"2012-10-08T13:36:35+04:00"},             {"_id":"50754f9d43749c0dd8000003","account_category":"cat1","balance":60000,"created_at":"2012-10-10T14:36:13+04:00","currency":"rub","name":"VTB","updated_at":"2012-10-12T22:42:57+04:00"}            ]}
    I write English by translator.

  5. #5
    Sencha User
    Join Date
    Oct 2012
    Posts
    18
    Answers
    1
    Vote Rating
    0
    Shaci is on a distinguished road

      0  

    Default


    Thank, i understand, that i have default value of defaultRootProperty = "children"

    (if i understand you, i good know javascript, but i learn sencha only few days)

    I have another question, what if i can't convert the respons.
    How i can do this with sencha, maybe in reader?

    For example, i want transform this json

    Code:
     [
    { id:1, name: "John"},
    {id:2, name: "Lopez"}
    ]
    to this:
    Code:
    {
    items: [
    { id:1, name: "John"},
    {id:2, name: "Lopez"}
    ]
    }
    or, which more important, i want add my own items, country name for example
    If i want, that people of Brazil are displayed under "Brazil item", and people from USA under "USA item", but i dont want do any changes on server side

    For example, transform to this:

    Code:
     [
    {id:"country", name:"USA"},
    { id:1, name: "John"},
    {id: "country", name:"Brazil"},
    {id:2, name: "Lopez"}
    ]

Thread Participants: 1

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi