1. #1
    Sencha User
    Join Date
    Dec 2007
    Location
    Budapest, Hungary
    Posts
    94
    Vote Rating
    1
    Answers
    1
    Zolcsi is on a distinguished road

      0  

    Default Answered: Inserting a record into an empty dataview fails

    Answered: Inserting a record into an empty dataview fails


    Hi everybody,

    I have a navigation view, inside it is a list, which pushes a form into the navigation view when tapped on an item. There is also a "new" button for adding new records to the list.
    If I tap an item I can edit it properly with my form. If I tap the new button when the list is populated with some data, then I can add a new record as well. But here is the problem: when the list is empty, sencha touch fails to add a record to the list. It throws me a rendering error. This is the exact message and stack trace:

    Code:
    Uncaught TypeError: Cannot read property 'getScroller' of undefined List.js?_dc=1413406501411:1101
    Ext.define.doRefresh List.js?_dc=1413406501411:1101
    Ext.define.onStoreAdd List.js?_dc=1413406501411:1304
    Ext.define.doFire Controller.js?_dc=1413406499291:199
    Ext.define.fire Controller.js?_dc=1413406499291:126
    Ext.define.doDispatchEvent Dispatcher.js?_dc=1413406499066:347
    Ext.define.dispatchEvent Dispatcher.js?_dc=1413406499066:328
    Ext.define.doFireEvent Observable.js?_dc=1413406499730:262
    Ext.define.fireEvent Observable.js?_dc=1413406499730:216
    Ext.define.insert Store.js?_dc=1413406501479:1281
    Ext.define.add Store.js?_dc=1413406501479:1223
    Ext.define.addData Store.js?_dc=1413406501479:1043
    Ext.define.oraResztvevoMentes Ora.js?_dc=1413406501300:170
    Ext.define.doFire Controller.js?_dc=1413406499291:199
    Ext.define.fire Controller.js?_dc=1413406499291:126
    Ext.define.doDispatchEvent Dispatcher.js?_dc=1413406499066:347
    Ext.define.dispatch ComponentDelegation.js?_dc=1413406499603:168
    Ext.define.publish ComponentDelegation.js?_dc=1413406499603:242
    Ext.define.doFire Controller.js?_dc=1413406499291:199
    Ext.define.fire Controller.js?_dc=1413406499291:126
    Ext.define.doDispatchEvent Dispatcher.js?_dc=1413406499066:347
    Ext.define.dispatchEvent Dispatcher.js?_dc=1413406499066:328
    Ext.define.doFireEvent Observable.js?_dc=1413406499730:262
    Ext.define.fireAction Observable.js?_dc=1413406499730:247
    Ext.define.onTap Button.js?_dc=1413406501395:644
    Ext.define.doFire Controller.js?_dc=1413406499291:199
    Ext.define.fire Controller.js?_dc=1413406499291:126
    Ext.define.doDispatchEvent Dispatcher.js?_dc=1413406499066:347
    Ext.define.dispatch Publisher.js?_dc=1413406499304:65
    Base.implement.callParent sencha-touch.js:4725
    Ext.define.dispatch Dom.js?_dc=1413406499272:300
    Ext.define.doPublish Dom.js?_dc=1413406499272:348
    Ext.define.publish Dom.js?_dc=1413406499272:307
    Base.implement.callSuper sencha-touch.js:4804
    Ext.define.publish TouchGesture.js?_dc=1413406499363:179
    Ext.define.onRecognized TouchGesture.js?_dc=1413406499363:164
    Ext.define.fire Recognizer.js?_dc=1413406499461:58
    Ext.define.onTouchEnd Tap.js?_dc=1413406499478:43
    Ext.define.invokeRecognizers TouchGesture.js?_dc=1413406499363:229
    Ext.define.onTouchEnd TouchGesture.js?_dc=1413406499363:406
    Ext.define.onEvent TouchGesture.js?_dc=1413406499363:134
    (anonymous function) sencha-touch.js:3217
    I am using Sencha Touch 2.4 with Sencha Architect 3.1
    This is the code I am using:
    Code:
    if(this.getOraResztvevoLista().getSelectionCount() === 0)
    {
        //New record
        this.getOraResztvevoLista().getStore().addData({
            loId: this.getLo().getValue(),
            loNev: this.getLo().getRecord().get('nev'),
            lovas: this.getLovas().getValue(),
            szobaId: this.getSzoba().getValue(),
            szobaNev: Ext.isEmpty(this.getSzoba().getValue()) ? '' : this.getSzoba().getRecord().get('nev'),
            megjegyzes: this.getMegjegyzes().getValue()
        });
    }
    else
    {
        //Updating an existing record
        var record = this.getOraResztvevoLista().getSelection()[0];
        record.set('loId', this.getLo().getValue());
        record.set('loNev', this.getLo().getRecord().get('nev'));
        record.set('lovas', this.getLovas().getValue());
        record.set('szobaId', this.getSzoba().getValue());
        record.set('szobaNev', Ext.isEmpty(this.getSzoba().getValue()) ? '' : this.getSzoba().getRecord().get('nev'));
        record.set('megjegyzes', this.getMegjegyzes().getValue());
    }
    this.getHomePanel().pop();
    If I comment out the addData() method, then the script runs without any errors. Of course the row doesn't get added that way.

    Any help is much appreciated!

  2. I have found the mistake, obviously it was my fault...

    When adding a new record I removed all the sub records from the list. At least that's what I wanted to do, but instead of this:
    this.getDataList().getStore().removeAll();

    I used this:
    this.getDataList().removeAll();

    Which I guess removed some components from the list, and that made it unable to work later when adding a new record to it.

  3. #2
    Sencha User
    Join Date
    Dec 2007
    Location
    Budapest, Hungary
    Posts
    94
    Vote Rating
    1
    Answers
    1
    Zolcsi is on a distinguished road

      0  

    Default


    I have found the mistake, obviously it was my fault...

    When adding a new record I removed all the sub records from the list. At least that's what I wanted to do, but instead of this:
    this.getDataList().getStore().removeAll();

    I used this:
    this.getDataList().removeAll();

    Which I guess removed some components from the list, and that made it unable to work later when adding a new record to it.

  4. #3
    Sencha - Support Team israelroldan's Avatar
    Join Date
    Nov 2011
    Location
    Den Haag, Netherlands
    Posts
    172
    Vote Rating
    17
    Answers
    21
    israelroldan will become famous soon enough

      0  

    Default


    Your findings are correct, removing the rows but leaving the store items causes an inconsistency that resulted in the error you describe.Thanks for updating the thread!
    Israel Roldàn | Senior Support Engineer

Thread Participants: 1