Results 1 to 4 of 4

Thread: Change JSON read data from "" to '\u00a0'

  1. #1
    Sencha User
    Join Date
    Feb 2010
    Posts
    21
    Vote Rating
    0
      0  

    Default Change JSON read data from "" to '\u00a0'

    I'm reading in data using a JSON reader to display in a combobox, which is in a grid.

    The incoming data has some fields that are blank: "".

    I'd like my script to map "" to '\u00a0' and correctly enter that data into my combobox.

    Some code:

    Reader:

    Code:
    var logReader = new Ext.data.JsonReader({
            root: 'Data',
            fields: [{
                name: 'logName',
                mapping: 'logName'
            }, {
                name: 'logLevel',
                mapping: 'logLevel'
            }]
        });
    combo store:
    Code:
        var levelComboStore = new Ext.data.ArrayStore({
            fields: ['logLevelComboValue', 'logLevelComboDisplay'],
            data: [['', '\u00a0'], ['TRACE', 'TRACE'], ['DEBUG', 'DEBUG'], ['INFO', 'INFO'], ['WARN', 'WARN'], ['ERROR', 'ERROR'], ['FATAL', 'FATAL'], ['OFF', 'OFF']]
        });
    combo:

    Code:
        var levelCombo = new Ext.form.ComboBox({
            store: levelComboStore,
            mode: 'local',
            forceSelection: true,
            triggerAction: 'all',
            lazyRender: true,
            typeAhead: true,
            typeAhead:50,
            valueField: 'logLevelComboValue',
            displayField: 'logLevelComboDisplay',
            valueNotFoundText: 'Value Not Found'
        });

  2. #2
    Ext User
    Join Date
    Dec 2007
    Posts
    95
    Vote Rating
    -1
      0  

    Default

    I would add a convert function to the field definition of your grid's store to change "" into \u00a0. see http://www.extjs.com/deploy/dev/docs...Ext.data.Field

  3. #3
    Sencha User
    Join Date
    Feb 2010
    Posts
    21
    Vote Rating
    0
      0  

    Default

    evanc, thanks I think this will work!

    However, I'm new to extJS and JS in general and I'm not sure how to compare v to ''.

    Here are my attempts, both of which haven't worked.

    Code:
        
    function blankToNBS(v, record){
            return (v == '') ? '\u00a0' : v;
    }
    Code:
    function blankToNBS(v, record){
            return !v ? '\u00a0' : v;
    }
    Any help?

    BTW,

    this is the JSON code:
    Code:
    "logLevel":""

  4. #4
    Ext User
    Join Date
    Dec 2007
    Posts
    95
    Vote Rating
    -1
      0  

    Default

    I assume that when you say '' you're indicating an invisible unicode string.

    try doing something like
    Code:
    if (v.charCodeAt(0) == 118) {
      //whatever
    }
    I don't know what the charcode for '' is but you should be able to find it experimentally using firebug, if nothing else.

Posting Permissions

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