Results 1 to 7 of 7

Thread: object + array + object

  1. #1
    Ext User
    Join Date
    Aug 2010
    Posts
    15
    Vote Rating
    0
      0  

    Default object + array + object

    Regards,

    I created an object containing an array containing an object:

    PHP Code:
    var obj 
             { 
                 
    param: [
                 {
    idealp:"aa",ideala:"aa"ideApp:"aa",tipApp:"aa"},
                 {
    idealp:"aa",ideala:"aa"ideApp:"aa",tipApp:"aa"},
                 {
    idealp:"aa",ideala:"aa"ideApp:"aa",tipApp:"aa"},
                 {
    idealp:"aa",ideala:"aa"ideApp:"aa",tipApp:"aa"},
                 {
    idealp:"aa",ideala:"aa"ideApp:"aa",tipApp:"aa"}
                 ]
             } 
    The problem is that I want the array is dynamic and can add rows as needed in a loop. In the example I am limited by five parameters and would like to create n.

    PHP Code:
    for (var index 0index 10index++) {  //insufficient array error (is undefined)
            
    obj.param[index].idealaindex,
            
    obj.param[index].idealpindex+1
        

    any ideas ?

  2. #2
    Sencha User
    Join Date
    Jun 2009
    Location
    Colorado
    Posts
    51
    Vote Rating
    0
      0  

    Default

    What exactly are you trying to do in the loop? The error is caused by trying to access an index of the array that does not exist.

  3. #3
    Sencha User
    Join Date
    Aug 2009
    Posts
    480
    Vote Rating
    4
      0  

    Default

    I don't get what you are trying to do...?

  4. #4
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    133
      0  

    Default

    So you want:
    Code:
    for (var index = 0; index < obj.param.length; index++) {
      obj.param[index].ideala = index;
      obj.param[index].idealp = index + 1;
    }
    (although I have no idea why)

  5. #5
    Ext User
    Join Date
    Aug 2010
    Posts
    15
    Vote Rating
    0
      0  

    Default

    sorry, I do not explained well.

    I have a store and is the store that fill in the array. But the store may have 5 or 20 records, so the array that I should have the same size as the store. the idea is:

    for (var index = 0; index <store.length; index++) { //insufficient array error (is undefined)
    obj.param[index].ideala= index,
    obj.param[index].idealp= index+1
    }

  6. #6
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    133
      0  

    Default

    You'll have to explain better.

    You have some data (obj) and you have a store. What do these two have to do with each other?

  7. #7
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890
    Vote Rating
    90
      0  

    Default

    Quote Originally Posted by occiso View Post
    Regards,

    I created an object containing an array containing an object:

    PHP Code:
    var obj 
             { 
                 
    param: [
                 {
    idealp:"aa",ideala:"aa"ideApp:"aa",tipApp:"aa"},
                 {
    idealp:"aa",ideala:"aa"ideApp:"aa",tipApp:"aa"},
                 {
    idealp:"aa",ideala:"aa"ideApp:"aa",tipApp:"aa"},
                 {
    idealp:"aa",ideala:"aa"ideApp:"aa",tipApp:"aa"},
                 {
    idealp:"aa",ideala:"aa"ideApp:"aa",tipApp:"aa"}
                 ]
             } 
    The problem is that I want the array is dynamic and can add rows as needed in a loop. In the example I am limited by five parameters and would like to create n.

    PHP Code:
    for (var index 0index 10index++) {  //insufficient array error (is undefined)
            
    obj.param[index].idealaindex,
            
    obj.param[index].idealpindex+1
        

    any ideas ?
    obj.param.push(// a new object);

Similar Threads

  1. How to load JsonStore object from an existing JSON object/array
    By guyza in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 16 Sep 2010, 2:50 PM
  2. Replies: 0
    Last Post: 21 Jun 2010, 9:17 AM
  3. Replies: 6
    Last Post: 1 Apr 2009, 8:12 AM
  4. Replies: 2
    Last Post: 25 Oct 2007, 6:06 AM
  5. json-object in array
    By humpdi in forum Ext 1.x: Help & Discussion
    Replies: 8
    Last Post: 9 Apr 2007, 8:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •