1. #1
    Sencha Premium Member Zdeno's Avatar
    Join Date
    Nov 2009
    Location
    Prague
    Posts
    389
    Vote Rating
    17
    Zdeno will become famous soon enough

      0  

    Default ArrayStore - idProperty

    ArrayStore - idProperty


    Is possible to use idProperty on model which is assign to arraystore?

    Code:
    Ext.define("Level", {
        extend : "Ext.data.Model",
        idProperty : 'value',
        fields : [
            { name: 'value', type: 'int' },
            { name: 'text', type: 'string' }
        ]
    });
    Code:
    var levelData = [];
    if (condition) {
        levelData.push(
            Ext.create('Level', {
                value : 10
                text : 'Text value'
            })
        );
    }
    Code:
    store : Ext.create('Ext.data.ArrayStore', {
        model : 'Level',
        data : levelData
    }),
    When i check data in the store, i see ID with value: "Level-ext-record-28". Am I doing anything wrong?

  2. #2
    Sencha - Community Support Team
    Join Date
    Jan 2012
    Posts
    1,376
    Vote Rating
    113
    vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all

      0  

    Default


    The id you mentioned is just the id of the model instance not record id. If you try <store>.getAt(0).getId() you will get the correct value.


    The reason why you get that id is that you directly create a model instance without supplying it an id. Looking at Model constructor, you will see the syntax of creating a new model instance. It is:
    Code:
        constructor: function(data, id, raw, convertedData) {
    Without id argument, framework will generate one.


    When you construct an array and supply it as data to construct an array store as you did in:
    Code:
    store : Ext.create('Ext.data.ArrayStore', {
        model : 'Level',
       data : levelData
    })
    the data will be parsed by reader. With each record that is already a model, it will be directly pushed into store. If the record that is not a model, reader will get record id which is based on idProperty, constructs a model instance by using the above syntax and push it into store. With these record, the model id will be Modelname + "-" + recordId which is determined basing on idProperty.


    If you fix your code as below, everything will be OK:
    Code:
    var levelData = [];
    if (condition) {
    //    levelData.push(
    //        Ext.create('Level', {
    //            value : 10
    //            text : 'Text value'
    //        })
    //    );
       levelData.push({
            value : 10
            text : 'Text value'
       });
    }

  3. #3
    Sencha Premium Member Zdeno's Avatar
    Join Date
    Nov 2009
    Location
    Prague
    Posts
    389
    Vote Rating
    17
    Zdeno will become famous soon enough

      0  

    Default


    This didnt really fix my problem. When I check level data array, i will get array of objects:
    Code:
    [Object {
        value = 10, 
        text = "Level 10"
    },
    Object {
        value = 20, 
        text = "Level 20"
    }]
    When I check array store with correct internalId (10, 20, ...), id is still generated. When I look deep into structure and expand tree with data property, I see very bad result:

    arraystore-problem.png
    Am I doing anything wrong?

  4. #4
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,581
    Vote Rating
    318
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      0  

    Default


    Ignore the id and internalId properties on the records, they don't do what you think they do. The actual id of a record is in the data and should be accessed via getId.

    Quite why you're using an ArrayStore isn't clear. An ArrayStore is for reading an array of arrays, which isn't what you have. In the case where the data is passed as records this won't be a problem but the reader won't really be doing anything. The idProperty is being interpreted by the model, not the reader on the store.

    Here are some working examples:

    Code:
    Ext.define("Level", {
        extend : "Ext.data.Model",
        idProperty : 'value',
        fields : [
            { name: 'value', type: 'int' },
            { name: 'text', type: 'string' }
        ]
    });
    
    var levelData = [];
    
    levelData.push(
        Ext.create('Level', {
            value : 10,
            text : 'Text value'
        })
    );
    
    console.log(levelData[0].getId());
    
    var store = Ext.create('Ext.data.ArrayStore', {
        model : 'Level',
        data : levelData
    });
    
    console.log(store);
    console.log(store.getAt(0).getId());
    Code:
    Ext.define("Level", {
        extend : "Ext.data.Model",
        idProperty : 'value',
        fields : [
            { name: 'value', type: 'int' },
            { name: 'text', type: 'string' }
        ]
    });
    
    var levelData = [];
    
    // Format the data to be read by an Array reader
    levelData.push([10, 'Text value']);
    
    var store = Ext.create('Ext.data.ArrayStore', {
        model : 'Level',
        data : levelData
    });
    
    console.log(store);
    console.log(store.getAt(0).getId());

  5. #5
    Sencha Premium Member Zdeno's Avatar
    Join Date
    Nov 2009
    Location
    Prague
    Posts
    389
    Vote Rating
    17
    Zdeno will become famous soon enough

      0  

    Default


    I dont have any fixed structure. Thats why I ask in previous post, if possible create new record by model. Array of arrays is badly readable - without model on same place you dont know which value represent 'text' or 'value'. I realized my mistake yesterday when I overwrited code to simple array of arrays. Significant information is for me following part:

    Ignore the id and internalId properties on the records, they don't do what you think they do. The actual id of a record is in the data and should be accessed via getId.

Thread Participants: 2

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi