Looks like we can't reproduce the issue or there's a problem in the test case provided.
  1. #1
    Sencha User p5hema2's Avatar
    Join Date
    May 2012
    Location
    Jena Germany
    Posts
    20
    Vote Rating
    1
    p5hema2 is on a distinguished road

      0  

    Default Bug in Ext.data.Store methods

    Bug in Ext.data.Store methods


    Ext version tested:
    • Sencha Touch 2.0 newest version
    Browser versions tested against:
    • browser independent
    DOCTYPE tested against:
    • ----
    Description:
    • Here is the problem, if you try to delete a item from Store with following code, the sencha code sometimes deletes a wrong value.

      searchHistory.find seems to crawl thru data.all ....
      removeAt crawls thru data.items ....

      the one is sorted by timestamp the other not.

      the first array isn't sorted but the second does, so the index values not matching and the wrong record is deleted.
    Steps to reproduce the problem:
    • see code below
    • create store with 2 field
    • field with data ( i inserted numbers like 1, 1, 1, 1, 12, 11, 13)
    • field with timestamp
    • sort store by timestamp desc
    • try to delete one item with the code below (the code was designed to delete all data by the given arguent, in my case q)
    The result that was expected:
    • see Description
    The result that occurs instead:
    • see Description
    Test Case:

    Code:
    Ext.define('fly.model.search.SearchHistory', {
        extend: 'Ext.data.Model',
        config: {
            fields: ['q', 'timestamp']
        }
    });
    
    
    Ext.define('fly.store.search.SearchHistory', {
        extend: 'Ext.data.Store',
        requires: 'fly.model.search.SearchHistory',
        config: {
            storeId: 'searchSearchHistory',
            model: 'fly.model.search.SearchHistory',
            proxy: {
                type: 'localstorage',
                id: 'searchHistory'
            },
            autoLoad: true,
            sorters: [{
                property: 'timestamp',
                direction: 'DESC'
            }]
         }
    });
    
    
    
    
    onSearchField: function (q) {
        //...  some more code
    
         var searchHistory = Ext.getStore('searchSearchHistory');
        //check if ths search already exists in the searchesStore
        var index = searchHistory.find('q', q);
        if (index != -1) {
            this.doDelete(index);
        }
    
        //...  some more code
    },
    
    doDelete: function (index) {
        Ext.getStore('searchSearchHistory').removeAt(index);
    },

    Possible fix:
    • my solution
      Code:
       onSearchField: function (q) {
           var searchHistory = Ext.getStore('searchSearchHistory');
           //check if ths search already exists in the searchesStore
           for (var i = 0; i < searchHistory.data.items.length; i++) {
               if (searchHistory.data.items[i].data.q == q) {
                   record = searchHistory.data.getAt(i);
                   searchHistory.remove(record)
                   i = 0;
               }
           }
       },
    Operating System:
    • Windows 8 and Windows 7

    greetings from germany
    and happy fixing ;-)

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,525
    Vote Rating
    872
    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


    Using 2.0.1.1, I came up with this fully runnable testcase that should describe the issue you brought up:

    Code:
    var store = new Ext.data.Store({
        fields  : ['text', 'num'],
        sorters : [
            {
                property  : 'num',
                direction : 'DESC'
            }
        ],
        data    : [
            { text : 'One',   num : 1  },
            { text : 'Two',   num : 2  },
            { text : 'Three', num : 3  },
            { text : 'Four',  num : 4  },
            { text : 'Five',  num : 5  },
            { text : 'Six',   num : 6  },
            { text : 'Seven', num : 7  },
            { text : 'Eight', num : 8  },
            { text : 'Nine',  num : 9  },
            { text : 'Ten',   num : 10 }
        ]
    });
    
    console.log('-- Before Remove');
    
    store.each(function(rec) {
        console.log(rec.get('text'));
    });
    
    var index = store.find('text', 'Eight');
    if (index !== -1) {
        store.removeAt(index);
    }
    
    console.log('-- After Remove');
    
    store.each(function (rec) {
        console.log(rec.get('text'));
    });
    Watching the console, I do indeed see that Eight was removed so I cannot reproduce this bug.
    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 p5hema2's Avatar
    Join Date
    May 2012
    Location
    Jena Germany
    Posts
    20
    Vote Rating
    1
    p5hema2 is on a distinguished road

      0  

    Default


    Hmm, i am looking at it, may i can shrink my code to give you my exaple

  4. #4
    Sencha User p5hema2's Avatar
    Join Date
    May 2012
    Location
    Jena Germany
    Posts
    20
    Vote Rating
    1
    p5hema2 is on a distinguished road

      0  

    Default


    Ok, found the error. Our Store was populated with new values before we deleted the data .

    Pls close this thread.

    Thanks anyway.
    Martin