Results 1 to 4 of 4

Thread: Loading selectfield from an external json file

  1. #1
    Sencha User riyaad's Avatar
    Join Date
    Jul 2011
    Location
    Cape Town
    Posts
    245
    Vote Rating
    2
      0  

    Default 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,326
    Vote Rating
    1297
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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
    245
    Vote Rating
    2
      0  

    Default 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
    245
    Vote Rating
    2
      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...

Posting Permissions

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