1. #1
    Sencha User
    Join Date
    Aug 2011
    Location
    Bangalore,IN
    Posts
    114
    Answers
    6
    Vote Rating
    0
    gameboy87 is on a distinguished road

      0  

    Default Answered: Loading XML values into ComboBox

    Answered: Loading XML values into ComboBox


    I have read all the documentation related to loading the values into Combo,XML reader....I really got frustrated....May I know What I went wrong in this code ?

    Code:
    Ext.onReady(function(){
    
    Ext.define('combo_m',{
      extend:'Ext.data.Model',
      fields:[
         { name:'city', mapping:'cityname > city'}
      ]
    });
    
    
    var store_combo = Ext.create('Ext.data.Store',{
                        model:'combo_m',
                        autoLoad:true,
                        proxy:{
                           type:'ajax',
                           url:'data.xml',
                           reader:{
                                type:'xml',
                                record:'cityname'
                           }
                        }
    });
    
    
    var combo = new Ext.form.ComboBox({
      fieldLabel:'City',
      labelWidth:40,
      name:'somedata',
      id:'somedata',
      queryMode:'local',
      triggerAction:'all',
      store:store_combo,
      renderTo:document.body,
      //typeAhead:true,
      displayField:'name',
      valueField:'name'
     });
    
    
    
    });

    And this is my XML file,

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
     <cityname>
      <city>Bangalore</city>
      <city>Chennai</city>
      <city>Mysore</city>
      <city>Mumbai</city>
      <city>Delhi</city>
      <city>Kolkata</city>
      <city>Pune</city>
      <city>Coimbatore</city>
     </cityname>

    The combo is not loading with this values. Please help.

  2. Your displayField and valueField is 'name', but your store does not contain any field 'name'. You'll want to change these to 'city'. Since you define cityname as your record and city as the field of that record, you should remove the mapping in the field definition. Your XML is also not defined correctly. You can't have multiple 'city' fields within your 'cityname' record. Here's a working example:

    Code:
    Ext.onReady(function() {
        Ext.define('combo_m', {
            extend: 'Ext.data.Model',
            fields: [{
                name: 'city'
            }]
        });
    
    
        var store_combo = Ext.create('Ext.data.Store', {
            model: 'combo_m',
            autoLoad: true,
            proxy: {
                type: 'ajax',
                url: 'data.xml',
                reader: {
                    type: 'xml',
                    record: 'cityname'
                }
            }
        });
    
    
        var combo = new Ext.form.ComboBox({
            fieldLabel: 'City',
            labelWidth: 40,
            name: 'somedata',
            id: 'somedata',
            queryMode: 'local',
            triggerAction: 'all',
            store: store_combo,
            renderTo: document.body,
            //typeAhead:true,
            displayField: 'city',
            valueField: 'city'
        });
    });

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <data>
     <cityname>
      <city>Bangalore</city>
     </cityname>
     <cityname>
      <city>Chennai</city>
     </cityname>
     <cityname>
       <city>Mysore</city>
     </cityname>
     <cityname>
      <city>Mumbai</city>
     </cityname>
     <cityname>
      <city>Delhi</city>
     </cityname>
     <cityname>
      <city>Kolkata</city>
     </cityname>
     <cityname>
      <city>Pune</city>
     </cityname>
     <cityname>
      <city>Coimbatore</city>
     </cityname>
    </data>

  3. #2
    Touch Premium Member
    Join Date
    Feb 2011
    Location
    NJ
    Posts
    311
    Answers
    59
    Vote Rating
    52
    droessner is a jewel in the rough droessner is a jewel in the rough droessner is a jewel in the rough

      0  

    Default


    Your displayField and valueField is 'name', but your store does not contain any field 'name'. You'll want to change these to 'city'. Since you define cityname as your record and city as the field of that record, you should remove the mapping in the field definition. Your XML is also not defined correctly. You can't have multiple 'city' fields within your 'cityname' record. Here's a working example:

    Code:
    Ext.onReady(function() {
        Ext.define('combo_m', {
            extend: 'Ext.data.Model',
            fields: [{
                name: 'city'
            }]
        });
    
    
        var store_combo = Ext.create('Ext.data.Store', {
            model: 'combo_m',
            autoLoad: true,
            proxy: {
                type: 'ajax',
                url: 'data.xml',
                reader: {
                    type: 'xml',
                    record: 'cityname'
                }
            }
        });
    
    
        var combo = new Ext.form.ComboBox({
            fieldLabel: 'City',
            labelWidth: 40,
            name: 'somedata',
            id: 'somedata',
            queryMode: 'local',
            triggerAction: 'all',
            store: store_combo,
            renderTo: document.body,
            //typeAhead:true,
            displayField: 'city',
            valueField: 'city'
        });
    });

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <data>
     <cityname>
      <city>Bangalore</city>
     </cityname>
     <cityname>
      <city>Chennai</city>
     </cityname>
     <cityname>
       <city>Mysore</city>
     </cityname>
     <cityname>
      <city>Mumbai</city>
     </cityname>
     <cityname>
      <city>Delhi</city>
     </cityname>
     <cityname>
      <city>Kolkata</city>
     </cityname>
     <cityname>
      <city>Pune</city>
     </cityname>
     <cityname>
      <city>Coimbatore</city>
     </cityname>
    </data>

  4. #3
    Sencha User
    Join Date
    Aug 2011
    Location
    Bangalore,IN
    Posts
    114
    Answers
    6
    Vote Rating
    0
    gameboy87 is on a distinguished road

      0  

    Default


    Thanks a lot droessner. That was much Helpful. I am guessing how to read the records with this config.

    Code:
    <?xml version="1.0" encoding="UTF-8"?> 
    <cityname>  
    <city>Bangalore</city> 
     <city>Chennai</city>  
    <city>Mysore</city> 
     <city>Mumbai</city> 
     <city>Delhi</city>
      <city>Kolkata</city>
      <city>Pune</city> 
     <city>Coimbatore</city>
     </cityname>
    Last edited by gameboy87; 20 Aug 2012 at 9:07 PM. Reason: Didn't include CODE tag

Thread Participants: 1

Tags for this Thread

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