1. #1
    Sencha User
    Join Date
    Apr 2013
    Posts
    34
    Vote Rating
    0
    Answers
    2
    jjaskols is on a distinguished road

      0  

    Default Answered: Problem updating content in DataItem/ListItem

    Answered: Problem updating content in DataItem/ListItem


    Hello,

    I ran into another issue that kept me wondering all day now.

    I want to change an image in a ListItem, depending on a data field in the list record. More precisely: "status", which can either be true or false, dictates if an image shows "On"- or "Off"-Symbols.

    I am updating the underlying datastore through this:

    Code:
    var img = Ext.ComponentQuery.query('x-groupdataitem')[index];
    var store = Ext.getStore('groupstore');
    var i = store.findExact('device_name', img._name._html);
    store.getAt(i).set('status', Boolean(JSON.parse(response.responseText)['newState'));
    This reliably updates the "status" field in the corresponding record. However, I continue to fail at the task of finding a way, so that the image changes according to the "status" field changes.

    I am using the updateRecord(record); function in the ListItem in the following way:

    Code:
    updateRecord: function(record) {
    if(record.data.status) {
      this.getStatusButton().setSrc('resources/icons/onbutton.jpg');
    } else {
      this.getStatusButton().setSrc('resources/icons/offbutton.jpg');
    }
    this.updateStatusButton(this.getStatusButton());
    this.callParent(arguments);
    }
    I get no errors, no mispelled syntax, and every field actually contains what its supposed to. Even the imgSrc field contains the RIGHT url!!!

    I would be grateful for any tips,
    Janik

  2. Try it like this and see if it works:

    Code:
    updateRecord: function(record) {
    this.callParent(arguments);
    if(record.get('status')) { //You Should always use the record.get() syntax
      this.getStatusButton().setSrc('resources/icons/onbutton.jpg');
    } else {
      this.getStatusButton().setSrc('resources/icons/offbutton.jpg');
    }
    
    this.updateStatusButton(this.getStatusButton()); //I don't think you even need this line.
    
    }

  3. #2
    Sencha User
    Join Date
    Apr 2012
    Posts
    164
    Vote Rating
    9
    Answers
    13
    in4p will become famous soon enough

      0  

    Default


    Try it like this and see if it works:

    Code:
    updateRecord: function(record) {
    this.callParent(arguments);
    if(record.get('status')) { //You Should always use the record.get() syntax
      this.getStatusButton().setSrc('resources/icons/onbutton.jpg');
    } else {
      this.getStatusButton().setSrc('resources/icons/offbutton.jpg');
    }
    
    this.updateStatusButton(this.getStatusButton()); //I don't think you even need this line.
    
    }

  4. #3
    Sencha User
    Join Date
    Apr 2013
    Posts
    34
    Vote Rating
    0
    Answers
    2
    jjaskols is on a distinguished road

      0  

    Default


    Yes, works like a charm. Thanks a lot!!!

    Thus: this.callParent must always be first!!!

    Oh and heads up, this.callParent() requires an array if its in the constructor. Is this always the case!?!

Thread Participants: 1

Tags for this Thread