1. #1
    Sencha User
    Join Date
    Aug 2012
    Posts
    11
    Vote Rating
    1
    reselbob is on a distinguished road

      0  

    Default Unanswered: Combobox not populating when changing stores

    Unanswered: Combobox not populating when changing stores


    Hi:

    I am trying to extact the data from an existing combobox, get distinct values in the data I have extracted and then reassign the distinct data to the combobox.

    First, I get the data by adding a handler for the AfterRender event of the combobox.

    onCategoryComboboxAfterRender: function(abstractcomponent, options){
    .
    .
    var itms = abstractcomponent.store.data.items;


    Then I get the values that are in the combobox, which are from the field, 'category' and put them in the array, cats.

    var cats = [];
    for(var t = 0;t< itms.length;t++){
    cats.push(itms[t].raw.category);

    }


    I get the distinct values from cats:

    var getUnique = function(arr){
    var a = [], l = arr.length;
    for(var i=0; i<l; i++) {
    for(var j=i+1; j<l; j++)
    if (arr[i] === arr[j]) j = ++i;
    a.push(arr[i]);
    }
    return a;
    };

    var dstnct = getUnique(cats)
    ;


    I create a model that has a field, 'value':

    Ext.define('tempComboModel', {
    extend: 'Ext.data.Model',
    config: {
    identifier: 'uuid',
    fields: [
    {name: 'value', type: 'string'}
    ]
    }
    });

    I create a store that uses the newly created model, 'tempComboModel':

    var store = Ext.create('Ext.data.Store', {
    storeId:'tempcmboStore',
    model: 'tempComboModel',
    queryMode:'local',
    autoLoad:true,
    proxy: {
    type: 'memory',
    reader: {
    type: 'json'
    }
    }
    });


    I assign the newly created store to the combobox:

    abstractcomponent.store = store;

    I put the distinct values into the newly assigned store:

    for(var i = 0; i< dstnct.length;i++)
    {
    abstractcomponent.getStore().add(new Ext.data.Record({value:dstnct[i]}));
    }


    I deploy and preview the code.

    There is no data in the combo. Also, Firefox reports two errors:

    TypeError: me.fields is undefined
    length = records.length;


    and

    TypeError: records is undefined
    length = records.length;

    I must be doing something very wrong. I will greatly appreciate any help anybody can offer.

  2. #2
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,625
    Vote Rating
    331
    Answers
    550
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      0  

    Default


    You're mixing all sorts of paradigms there. I'm guessing you're using ExtJS 4 so I've moved this thread to the ExtJS 4 Q&A forum.

    Why are you doing this in an afterrender listener? Why not just do it when the store loads?

    To grab unique values from a store you could use something like:

    Code:
    var values = combobox.getStore().collect('category');
    I wouldn't use a config block when defining a model if I were you. That may be the way to do it in Touch but in ExtJS you're asking for trouble. Just specify the config options directly on the class.

    This bit appears to be from ExtJS 3:

    Code:
    new Ext.data.Record({value:dstnct[i]})
    Ext.data.Record is just an alternative name for Ext.data.Model but you should probably be creating instances of tempComboModel instead (or just passing the record configs to the add method).

    This line is a little too optimistic:

    Code:
    abstractcomponent.store = store;
    The store is bound to the combobox, updating that single property won't update all of the other stuff like the listeners. To 'update' the store for a combobox the best way is to update the contents of the store rather than trying to change the store itself. You can either clear the contents of the store and add the unique entries or alternatively just purge the duplicates.

  3. #3
    Sencha User
    Join Date
    Aug 2012
    Posts
    11
    Vote Rating
    1
    reselbob is on a distinguished road

      0  

    Default


    Thank you, skirtle!

    I've learned a lot from your writing.

Thread Participants: 1

Tags for this Thread