1. #1
    Sencha User riyaad's Avatar
    Join Date
    Jul 2011
    Location
    Cape Town
    Posts
    240
    Vote Rating
    1
    riyaad is on a distinguished road

      0  

    Default Loading selectfield from an external json file

    Loading selectfield from an external json file


    Hi Sencha People

    Is there a way to populate a select field by means of an external json file?

    Code:
            var store = Ext.create('Ext.data.Store', {
                model: 'ListItems',
                storeId: 'itemStore',
                proxy: {
                    type: 'ajax',
                    url: 'itemList.json',
                    reader: {
                        type: 'json'
                    }
                },
                autoLoad: true
            });
    then doing ...

    Code:
            var item_ddn = new Ext.field.Select({
                name: 'item_ddn',
                label: 'Items Listed:',
                store: store
            });
    How does one bind the the item_id to the item_name (as in the JSON below) and list it?

    JSON code...

    Code:
    [
       {
          "item_id" : "113",
          "item_name" : "Metro Goldwyn Mayer"
       },
       {
          "item_id" : "106",
          "item_name" : "M-Net Action"
       }
    ]
    **Appreciated**

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    35,704
    Vote Rating
    751
    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

      0  

    Default


    Set the valueField config to 'item_id' and the displayField config to 'item_name' on your Select field. I would also set the idProperty on your Model to 'item_id' and you should have things setup pretty well. One last thing instead of doing 'new Ext.field.Select', you should do the ST2 way and do "Ext.create('Ext.field.Select' "
    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 riyaad's Avatar
    Join Date
    Jul 2011
    Location
    Cape Town
    Posts
    240
    Vote Rating
    1
    riyaad is on a distinguished road

      0  

    Default Awesomeness

    Awesomeness


    Hi Mitchell Simoens,

    Brilliant - thank you again. I did some more reading, had some more coffee and trial'n error sessions and got it working nicely ...

    Here's the code (for anyone else out there looking for this) ... pretty straight forward once you get the hang of it.

    Code:
    Ext.application({
        name: 'Dynamic Menu',
    
    
        launch: function() {
    
    
            Ext.define('MenuItems', {
                extend: 'Ext.data.Model',
                idProperty: 'item_id',
                  fields: [
                    {name: 'item_id',   type: 'string'},
                    {name: 'item_name', type: 'string'}
                ]
            });
    
    
            var store = Ext.create('Ext.data.Store', {
                model: 'MenuItems',
                storeId: 'MenuStore',
                proxy: {
                    type: 'ajax',
                    url: 'menu.json',
                    reader: {
                        type: 'json'
                    }
                },
                autoLoad: true
            });
    
    
            var bundle_ddn = Ext.create('Ext.field.Select', {
                name: 'item_ddn',
                label: 'Bouquet:',
                valueField: 'item_id',
                displayField: 'item_name',
                store: store
            });
    
    
            var formBase = {
                scroll: 'vertical',
                title: 'Settings',
                items: [ bundle_ddn ]
            };
    
    
            Ext.create('Ext.tab.Panel', {
                fullscreen: true,
                items: [ formBase ]
            });
    
    
        }
    });
    


    Regards,
    Riyaad

  4. #4
    Sencha User riyaad's Avatar
    Join Date
    Jul 2011
    Location
    Cape Town
    Posts
    240
    Vote Rating
    1
    riyaad is on a distinguished road

      0  

    Default


    PS: Does anyone know if this has been resolved?
    http://www.sencha.com/forum/showthre...-no-selection.

    I'm assuming there's yet to be a fix for STv2 as I'm getting the same behavior...

Thread Participants: 1

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar