Results 1 to 2 of 2

Thread: Loding nested data from xml to model (or store)

  1. #1
    Sencha User
    Join Date
    Jan 2012
    Posts
    2

    Default Loding nested data from xml to model (or store)

    Hello, I need load data from nested xml to model (or store).
    For xml:
    HTML Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <graph id="1" name="Voltage" >
    <d t="1353923747" v="32" />
    <d t="1353923807" v="57" />
    <d t="1353923867" v="73" />
    <d t="1353923927" v="28" />
    </graph>
    I try this code (as in the guide)
    PHP Code:
    Ext.define('MyGraph', {
                
    extend'Ext.data.Model',
                
    fields: [
                    {
    name'id',  type'integer'mapping '@id'},
                       {
    name'name'type'string',   mapping '@name' }
                ],
                
    proxy: {
                    
    type'ajax',
                    
    actionMethods'POST',
                    
    noCachefalse,
                    
    pageParam '',
                    
    startParam'',
                    
    limitParam'',
                    
    extraParams: {  
                        
    querytype'getgraph',
                    },
                    
    url 'server/graph.php',
                    
    reader:{
                            
    type'xml',
                            
    record'graph',
                            
    root  'graph'
                    
    }
                },

                
    hasMany'MyData' // shorthand for { model: 'MyData', name: 'mydatas' }
            
    });

            
    Ext.define('MyData', {
                
    extend'Ext.data.Model',
                
    fields:[
                    {
    name'time',  type'integer'mapping '@t'dateFormat'timestamp'},
                       {
    name'value'type'float',   mapping '@v' }
                ],
                
    belongsTo'MyGraph'
            
    });

            
    MyGraph.load(1, {
                
    success: function(elem) {
                    
    console.log("Graph: " elem.get('name'));
                    
    console.log(elem);

                    
    elem.mydatas().each(function(data) {
                        
    console.log("Data: " data.get('value'));
                    });
                }
            }); 
    But store "mydatas" is empty after load. Why? How repair this?
    Thank you.

  2. #2
    Sencha User
    Join Date
    Jan 2012
    Posts
    2

    Default

    Solving:
    Code:
    Ext.define('MyGraph', {
                extend: 'Ext.data.Model',
                fields: [
                    {name: 'id',  type: 'integer', mapping : '@id'},
                       {name: 'name', type: 'string',   mapping : '@name' }
                ],
                proxy: {
                    type: 'ajax',
                    actionMethods: 'POST',
                    noCache: false,
                    pageParam : '',
                    startParam: '',
                    limitParam: '',
                    extraParams: {  
                        querytype: 'getgraph',
                        element: 1000  
                    },
                    url : 'server/graph.php',
                    reader:{
                            type: 'xml',
                            record: 'graph',
                            root  : 'graph'
                    }
                },
    
                //hasMany: 'MyData' // shorthand for { model: 'MyData', name: 'mydatas' }
                hasMany: { model: 'MyData', name: 'time' }
            });
    
            Ext.define('MyData', {
                extend: 'Ext.data.Model',
                fields:[
                    {name: 'time',  type: 'integer', mapping : '@t', dateFormat: 'timestamp'},
                       {name: 'value', type: 'float',   mapping : '@v' }
                ],proxy: {
                    type: 'memory',
                    reader: {
                        type: 'xml',
                        root: 'ds',
                        record: 'd'
                    }
                },
                belongsTo: 'MyGraph'
            });
    
            MyGraph.load(1, {
                success: function(elem) {
                    console.log("Graph: " + elem.get('name'));
                    console.log(elem);
    
                    elem.time().each(function(data) {
                        console.log(data.get('value')+':'+data.get('time'));
                    });
                }
            });
    and add node "ds" for xml:
    HTML Code:
    <?xml version="1.0" encoding="UTF-8"?> <graph id="1" name="Voltage" >
     <ds>   <d t="1353923747" v="32" />   <d t="1353923807" v="57" />   <d t="1353923867" v="73" />   <d t="1353923927" v="28" /> </ds>
    </graph>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •