Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Sencha User
    Join Date
    Jan 2008
    Location
    Bexhill-on-Sea, East Sussex, ENGLAND
    Posts
    21
    Vote Rating
    0
    pmahoney is on a distinguished road

      0  

    Default List item not getting model assciation data as part of values property

    List item not getting model assciation data as part of values property


    REQUIRED INFORMATION

    Ext version tested:
    • Touch 2.0.0

    Browser versions tested against:
    • Chrome
    • Safari 4
    • iPhone

    DOCTYPE tested against:
    • As produced by of the box ST2.00

    Description:
    • I have a list with a store for a model with a hierarchy or one-to-many data associations. The store is loaded from a remote XML data source. When the store is reloaded with data, list items are retrieved from a cache and updated with the new data (prepared so all associated date is present for the template), or new existing items in the list are updated with the new date (but this data is not prepared so the associated data is missing.

    Steps to reproduce the problem:
    • Reload a store with new data for a list already built for old data. Data model has to have data associations for this bug to manifest.

    The result that was expected:
    • List with new data including that from associated data.

    The result that occurs instead:
    • Javascript exception as template tries to access non-existent data

    Test Case:
    • Sorry, far too complex to give here.... BUT I have a fix. See below.

    HELPFUL INFORMATION

    Debugging already done:
    • I believe the error is in Ext.dataview.element.List

    Possible fix:

    Code:
    //Line 74 was:
    //data = record.data,
    
    //Line 74 now:
    data = dataview.prepareData(record.getData(true), dataview.getStore().indexOf(record), record),
    This code change reflects the code in Ext.dataview.element.container(Line 191), which is executed when reusing an item from the cache.

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,347
    Vote Rating
    846
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    All prepareData does is return the data after putting the index on the data. You can override the prepareData to get the association from the record, remember, assocaition data is not going to be part of the record data but you have to use the getter method to get the association data.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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
    Join Date
    Jan 2008
    Location
    Bexhill-on-Sea, East Sussex, ENGLAND
    Posts
    21
    Vote Rating
    0
    pmahoney is on a distinguished road

      0  

    Default


    I wonder if I may ask for more clairification?

    It may be the the call to prepare data only does what you say. But one of the parameters passed is 'record.getData(true), ' and this pulls in the associated data.

    I took this line verbatim from Ext.dataview.element.Container, which is executed when pulling in items from the cache when building a List. The problem was that when the list is refreshed with new data from the store, the data of existing list items was replaced with the new data, but said data did not include the associated data... I hope that last sentence made sense :-)

    Perhaps the fix is just to call record.getData(true), the rest being redundant.

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,347
    Vote Rating
    846
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Here is the prepareData method in the DataView (List doesn't override this)

    Code:
        /**
         * Function which can be overridden to provide custom formatting for each Record that is used by this
         * DataView's {@link #tpl template} to render each node.
         * @param {Object/Object[]} data The raw data object that was used to create the Record.
         * @param {Number} recordIndex the index number of the Record being prepared for rendering.
         * @param {Ext.data.Model} record The Record being prepared for rendering.
         * @return {Array/Object} The formatted data in a format expected by the internal {@link #tpl template}'s overwrite() method.
         * (either an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'}))
         */
        prepareData: function(data, index, record) {
            data.xindex = index + 1;
            return data;
        },
    As you can see it really doesn't do much. You can override it to mix in the associated data as you have access to the record.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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.

  5. #5
    Sencha User
    Join Date
    Jan 2008
    Location
    Bexhill-on-Sea, East Sussex, ENGLAND
    Posts
    21
    Vote Rating
    0
    pmahoney is on a distinguished road

      0  

    Default


    Hi, I know we have a time difference... but do you ever get time off?

    I really need to know why record.getDate(true) is called when installing an item into a list from the cache. Bit is not called when a pre-existing list item is updated with a new data.

    Until I made this change I was getting javascript exceptions due to the associated data not being pulled into the values passed to the item template. Some items were okay, others were not. My tracing through the code showed it occurred when reloading the store, which refreshes the list. Any re-used items did not have complete data, any added items did. At least that's what my anaylsis suggested.. but I'm still a novice when it comes to the framework.

  6. #6
    Sencha User Sharkanana's Avatar
    Join Date
    Nov 2011
    Location
    Charlotte, NC
    Posts
    39
    Vote Rating
    0
    Sharkanana is on a distinguished road

      0  

    Default


    I have the same problem as pmahoney, and Mitch's answer doesn't really address it.

    I have a list that shows records from a store that has an association.
    I override prepareData to add the association's data that I use in the itemTpl.
    I open a form and save changes to one of the list's records, changing an association.
    The prepared data fields are NOT updated in data used for the list, but other fields are.
    Calling list.refresh() or list.getStore().load does not work.

    Any suggestions?

Thread Participants: 2