Hybrid View

  1. #1
    Sencha User
    Join Date
    Sep 2012
    Posts
    55
    Vote Rating
    0
    bunty is on a distinguished road

      0  

    Default Unanswered: Populating Combo using XML as data source

    Unanswered: Populating Combo using XML as data source


    Below is the XML format:

    Code:
    <customers>	<customer>
    		<name>Customer1</name>
    	</customer>
    	<customer>
    		<name>Customer2</name>
    	</customer>
    	<customer>
    		<name>Customer3</name>
    	</customer>
    </customers>

    I want to load the customer names in a combo reading the above XML file. Below is the code I tried:


    Code:
    Ext.require('Ext.tab.*');
    
    Ext.define('Customer',{
        extend: 'Ext.data.Model',
        fields: [
            { name: 'name', type: 'string' }
        ]
    });
    
    
    var customerStore = Ext.create('Ext.data.XmlStore', {
    	autoLoad: true,
        url: '/XML/xml/customer.xml',
        fields: ['name'],
        record: 'customer'
    });
    
    
    Ext.define('CustomerCombo', {
        extend: 'Ext.form.field.ComboBox',
        alias: 'widget.customercombo',
        allowBlank: false,
        queryMode: 'local',
        valueField: 'id',
        displayField: 'name',
        store: customerStore
    });
    
    
    Ext.onReady(function(){
    	Ext.tip.QuickTipManager.init();
        Ext.widget('panel', {
        	renderTo: 'pan1',
            title: 'Basic Panel',
            width:600,
            height:100,
            defaults: {
                bodyPadding: 10,
                border: false,
                xtype: 'panel',
                layout: 'anchor'
            },
        	layout: 'hbox',
        	pack: 'end',
            items: [{
                	  fieldLabel: 'Customer',
                	  xtype: 'customercombo',
                	  width: 234,
                	  margin: '5 5 5 5'
                   }]            
        });  
    });
    But the code is not working. The Drop down is empty and an exception is thrown in Chrome console:

    Uncaught TypeError: Cannot call method 'indexOf' of undefined

    Please help

    Regards,

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,791
    Answers
    3465
    Vote Rating
    833
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      1  

    Default


    Try this:

    Code:
    Ext.define('Customer', {
        extend : 'Ext.data.Model',
    
        fields : [
            { name : 'name', type : 'string' }
        ]
    });
    
    Ext.define('CustomerCombo', {
        extend       : 'Ext.form.field.ComboBox',
        alias        : 'widget.customercombo',
    
        allowBlank   : false,
        queryMode    : 'local',
        valueField   : 'id',
        displayField : 'name'
    });
    
    Ext.onReady(function() {
    
        var customerStore = Ext.create('Ext.data.Store', {
            autoLoad : true,
            model    : 'Customer',
            proxy    : {
                type   : 'ajax',
                url    : '/XML/xml/customer.xml',
                reader : {
                    type   : 'xml',
                    record : 'customer'
                }
            }
        });
    
        Ext.widget('panel', {
            renderTo : 'pan1',
            title    : 'Basic Panel',
            width    : 600,
            height   : 100,
            defaults : {
                bodyPadding : 10,
                border      : false,
                xtype       : 'panel',
                layout      : 'anchor'
            },
            layout   : 'hbox',
            pack     : 'end',
            items    : [
                {
                    fieldLabel : 'Customer',
                    xtype      : 'customercombo',
                    width      : 234,
                    margin     : '5 5 5 5',
                    store      : customerStore
                }
            ]
        });
    
    });
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Sep 2012
    Posts
    55
    Vote Rating
    0
    bunty is on a distinguished road

      0  

    Default


    Thanks for the help, its woking fine.

    I modified the xml with namespaces for each and every element like this:

    Code:
    <c:customers>    <e:customer>
    		<p:name>Customer1</p:name>
    	</e:customer>
    	<e:customer>
    			<p:name>Customer2</p:name>
    	</e:customer>
    	<e:customer>
    			<p:name>Customer3</p:name>
    	</e:customer>
    </c:customers>
    And modified the code like this:

    Code:
    Ext.define('Customer', {    extend : 'Ext.data.Model',
    
    
        fields : [
            { name : 'p:name', type : 'string' }
        ]
    });
    
    
    Ext.define('CustomerCombo', {
        extend       : 'Ext.form.field.ComboBox',
        alias        : 'widget.customercombo',
    
    
        allowBlank   : false,
        queryMode    : 'local',
        valueField   : 'id',
        displayField : 'p:name'
    });
    
    
    Ext.onReady(function() {
    
    
        var customerStore = Ext.create('Ext.data.Store', {
            autoLoad : true,
            model    : 'Customer',
            proxy    : {
                type   : 'ajax',
                url    : '/XML/xml/customer.xml',
                reader : {
                    type   : 'xml',
                    record : 'e:customer'
                }
            }
        });
    
    
        Ext.widget('panel', {
            renderTo : 'pan1',
            title    : 'Basic Panel',
            width    : 600,
            height   : 100,
            defaults : {
                bodyPadding : 10,
                border      : false,
                xtype       : 'panel',
                layout      : 'anchor'
            },
            layout   : 'hbox',
            pack     : 'end',
            items    : [
                {
                    fieldLabel : 'Customer',
                    xtype      : 'customercombo',
                    width      : 234,
                    margin     : '5 5 5 5',
                    store      : customerStore
                }
            ]
        });
    
    
    });
    But did not work again.

    Initially thought that with or without namespace, the code should be same by changing the names only but its not like that

    Any help on this please?

  4. #4
    Sencha User
    Join Date
    Sep 2012
    Posts
    55
    Vote Rating
    0
    bunty is on a distinguished road

      0  

    Default


    any inputs on this?

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