2 Replies Latest reply on Dec 5, 2007 9:21 AM by luciewong

    Define and write "Object" dynamic

    luciewong
      Hi,
      when I understand it right, the item added to the DataGrid must be an Object.

      The following will put "Chase" in the column "name" and "30" in the column "age";

      var item_obj:Object = {name:"Chase", age:30};
      my_dg.addItemAt(0, item_obj);

      But this is hard coded.
      I do not have the value <name> nor the value >Chase<.
      Both items are coming dynamically from an ASP.

      ASP writes out column names, my Headers like:

      CName0 = ID
      CName1 = Name
      CName2 = Age ….and so on


      While >Chase< in the Code sample above I can probably manage, but how should I write >name< that I don't get an object Error?

      Thank you for your Help.

      regards,
      Luciewong
        • 1. Re: Define and write &quot;Object&quot; dynamic
          Level 7
          var item_obj:Object = {name:"Chase", age:30};

          can also be written

          var col0 ="name";
          var col1 ="age";
          var item_obj:Object = {};
          item_obj[col0] = "Chase";
          item_obj[col1] = 30;


          • 2. Re: Define and write &quot;Object&quot; dynamic
            luciewong Level 1
            Thank you Raymond,
            this looks good, I will try.
            The problem I see is only,
            1. I don't know how many columns ASP writes out, so I cannot define like var col0, var col1.../ I guess I must create dynamic String objects with a for loop
            2. each column has for ex. 100 records, they come in like ID0 to ID100 + formBox0 to formBox100 and so on...,

            ASP writes>
            Column names:
            cName0=ID&
            cName1=formBox&
            cName2=formID&
            cName3=formName ...and so on

            Column values for the first record:
            ID0=46&
            formBox0=Default&
            formID0=0&
            formName0=0&....and so on

            So a second record would look like:[records can be also arrays]
            ID1=46&
            formBox1=Default,xx&
            formID1=0,0,1,&
            formName1=0&....and so on

            Thank you for your help.
            Luciewong