Loading ...
Sorry, an error occurred while loading the content.

Re: [json] json as js variable

Expand Messages
  • Matthew Morley
    You would have to do something more than a simple translation. If your end goal was to directly reference fields values by name, you would need to do an end
    Message 1 of 19 , Dec 18, 2006
    • 0 Attachment
      You would have to do something more than a simple translation.

      If your end goal was to directly reference fields values by name, you would
      need to do an end translation back to the object format in which you were
      trying to avoid by duplicating names. Just a loop to recreate the data
      object from the two arrays.

      You have the knowledge of the fields names and could do your looping in
      another manner, without direct reference anyway. Depends how exposed it is I
      suppose and what level of work you want consumers of the data to do/know. I
      found gzip an easier alternative than object rebuilding when looking at
      performance in my projects

      Depending on the size of your data and lots of other items, it is likely to
      be faster for transmitting due to reduced payload, but it requires you to
      deal with the arrays and not objects unless you rebuild them.

      var row = MyStuff.u80020;
      var field_ISWEATHER = 3;
      var val = MyStuff.u80020[field_ISWEATHER];

      --
      Matthew P. C. Morley
      MPCM Technologies Inc.


      [Non-text portions of this message have been removed]
    • Mark Ireland
      Hopefully I can clear all this up. First I wanted to save on whitespace by avoiding var myArray = new Array; cfloop var myArray[myIndex] = new Array;
      Message 2 of 19 , Dec 18, 2006
      • 0 Attachment
        Hopefully I can clear all this up. First I wanted to save on whitespace by
        avoiding
        var myArray = new Array;
        cfloop
        var myArray[myIndex] = new Array;
        myArray[myIndex]['mycolumnName1']=#myQuery.myColumn1#;
        myArray[myIndex]['mycolumnName2']=#myQuery.myColumn2#;
        etc
        /cfloop

        Then I thought I could dynamically name form elements and get stuff from a
        js object that I could reference with dot notation. (with myIndex as the id
        of the element) Most of the stuff in the object is just flags that determine
        how the page behaves.

        If my goal is the shrink the page size what is the better approach?

        Thanks


        >From: "Matthew Morley" <WickedLogic@...>
        >Reply-To: json@yahoogroups.com
        >To: json@yahoogroups.com
        >Subject: Re: [json] json as js variable
        >Date: Mon, 18 Dec 2006 06:50:37 -0500
        >
        >You would have to do something more than a simple translation.
        >
        >If your end goal was to directly reference fields values by name, you would
        >need to do an end translation back to the object format in which you were
        >trying to avoid by duplicating names. Just a loop to recreate the data
        >object from the two arrays.
        >
        >You have the knowledge of the fields names and could do your looping in
        >another manner, without direct reference anyway. Depends how exposed it is
        >I
        >suppose and what level of work you want consumers of the data to do/know. I
        >found gzip an easier alternative than object rebuilding when looking at
        >performance in my projects
        >
        >Depending on the size of your data and lots of other items, it is likely to
        >be faster for transmitting due to reduced payload, but it requires you to
        >deal with the arrays and not objects unless you rebuild them.
        >
        >var row = MyStuff.u80020;
        >var field_ISWEATHER = 3;
        >var val = MyStuff.u80020[field_ISWEATHER];
        >
        >--
        >Matthew P. C. Morley
        >MPCM Technologies Inc.
        >
        >
        >[Non-text portions of this message have been removed]
        >

        _________________________________________________________________
        Advertisement: Meet Sexy Singles Today @ Lavalife - Click here
        http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Flavalife9%2Eninemsn%2Ecom%2Eau%2Fclickthru%2Fclickthru%2Eact%3Fid%3Dninemsn%26context%3Dan99%26locale%3Den%5FAU%26a%3D23769&_t=754951090&_r=endtext_lavalife_dec_meet&_m=EXT
      • Matthew Morley
        It would depend on what you mean by page and how much data you are dealing with. 3-10kb range might not make a huge difference on download, 20-300kb might. Run
        Message 3 of 19 , Dec 19, 2006
        • 0 Attachment
          It would depend on what you mean by page and how much data you are dealing
          with. 3-10kb range might not make a huge difference on download, 20-300kb
          might. Run some tests and time them in js, just keep in mind that they will
          vary from machine to machine greatly. I keep a 433mhz celeron laptop around
          to make sure I don't lose sight of performance too much.

          If you are worried about transmission speed and you have a fairly big set of
          data going, consider sizing it down. I know it sounds simple, but the
          fastest way to speed up anything is to do less; less data, less parsing.
          Don't optimize and worry about speed until you can prove it is running
          slowly and that the program is only `thinking` as much as it needs to.

          If that is not possible or desired, look at compressing the output with
          something like gzip if the browser supports it, but the numbers all get down
          to your data set. Using objects vs an object with an array of results and an
          array of keys is just a matter for the code/coder. Depends who your consumer
          is. If you want an object, send an object, and compress the communication
          would be my stance.

          Are you generating raw js right into the initial page? If yes, consider
          moving it out into a separate request. That way you can do initial loads and
          refresh with the data as it becomes available.

          --
          Matthew P. C. Morley
          MPCM Technologies Inc.


          [Non-text portions of this message have been removed]
        • Atif Aziz
          I think I know what you re looking for here. Suppose the following table: var table = { columns : [ FirstName , LastName ], rows : [ [ Mickey , Mouse
          Message 4 of 19 , Dec 19, 2006
          • 0 Attachment
            I think I know what you're looking for here. Suppose the following
            table:

            var table = {
            "columns" : [ "FirstName", "LastName" ],
            "rows" : [
            [ "Mickey", "Mouse" ],
            [ "Donald", "Duck" ],
            [ "Minnie", "Mouse" ]
            ]
            };

            Suppose further a function we add to the Array object's prototype:

            Array.prototype.toObject = function(names)
            {
            var o = {};
            for (var i = 0; i < names.length; i++)
            o[names[i]] = i < this.length ? this[i] : null;

            return o;
            }

            Now you can conveniently convert any row of the table into an object in
            one swell swoop like this:

            var o = table.rows[1].toObject(table.columns);

            This gives you non-repeating column names in the original table
            definition in JSON, which may be useful to keep the data on the wire
            small, yet object-like access (dot-syntax) to a row once in script.

            Hope this help.

            -----Original Message-----
            From: json@yahoogroups.com [mailto:json@yahoogroups.com] On Behalf Of
            Mark Ireland
            Sent: Sunday, December 17, 2006 11:19 PM
            To: json@yahoogroups.com
            Subject: Re: [json] json as js variable


            Thanks, that got it working.

            Now I am wondering if there is some alternative to repeating the column
            names in every object.

            >From: "Matthew Morley" <WickedLogic@...
            <mailto:WickedLogic%40gmail.com> >
            >Reply-To: json@yahoogroups.com <mailto:json%40yahoogroups.com>
            >To: json@yahoogroups.com <mailto:json%40yahoogroups.com>
            >Subject: Re: [json] json as js variable
            >Date: Mon, 11 Dec 2006 06:41:03 -0500
            >
            >*Identifiers* are names for constants, variables, functions, loop
            labels,
            >objects and classes. The first character must be an ASCII letter,
            >underscore
            >or dollar sign. Following characters can also include digits.
            >
            >Even 'u80020' will do. You can only use numeric indexes if you are
            >producing
            >an array.
            >
            >--
            >Matthew P. C. Morley
            >
            >
            >[Non-text portions of this message have been removed]
            >

            __________________________________________________________
            Join the millions of Australians using Live Search. Try live.com.au
            http://ninemsn.com.au/share/redir/adTrack.asp?mode=click&clientID=740&re
            ferral=million&URL=http://live.com.au
            <http://ninemsn.com.au/share/redir/adTrack.asp?mode=click&clientID=740&r
            eferral=million&URL=http://live.com.au>
          • Mark Ireland
            This is the right general idea but . . ... I am thinking: var myJSObject =
            Message 5 of 19 , Dec 20, 2006
            • 0 Attachment
              This is the right general idea but . . ...

              I am thinking:
              var myJSObject =
              {"RECORDCOUNT":3,"UNIQUEIDS":["js73012","js73016","js73029"],"COLUMNNAMES":["myColumnName1","myColumnName2","myColumnName3",.
              . ...],"js73012":{"CURRENTROW":1,"c1":9,"c2":2006,"c3":007,. . ....}

              all so I can build a table in a form with dynamically named checkboxs.

              But am I reinventing the wheel here? Should I be using stuff from
              prototype.js?


              >From: "Atif Aziz" <atif.aziz@...>
              >Reply-To: json@yahoogroups.com
              >To: <json@yahoogroups.com>
              >Subject: RE: [json] json as js variable
              >Date: Tue, 19 Dec 2006 14:30:48 +0100
              >
              >I think I know what you're looking for here. Suppose the following
              >table:
              >
              >var table = {
              > "columns" : [ "FirstName", "LastName" ],
              > "rows" : [
              > [ "Mickey", "Mouse" ],
              > [ "Donald", "Duck" ],
              > [ "Minnie", "Mouse" ]
              > ]
              >};
              >
              >Suppose further a function we add to the Array object's prototype:
              >
              >Array.prototype.toObject = function(names)
              >{
              > var o = {};
              > for (var i = 0; i < names.length; i++)
              > o[names[i]] = i < this.length ? this[i] : null;
              >
              > return o;
              >}
              >
              >Now you can conveniently convert any row of the table into an object in
              >one swell swoop like this:
              >
              >var o = table.rows[1].toObject(table.columns);
              >
              >This gives you non-repeating column names in the original table
              >definition in JSON, which may be useful to keep the data on the wire
              >small, yet object-like access (dot-syntax) to a row once in script.
              >
              >Hope this help.
              >
              >-----Original Message-----
              >From: json@yahoogroups.com [mailto:json@yahoogroups.com] On Behalf Of
              >Mark Ireland
              >Sent: Sunday, December 17, 2006 11:19 PM
              >To: json@yahoogroups.com
              >Subject: Re: [json] json as js variable
              >
              >
              >Thanks, that got it working.
              >
              >Now I am wondering if there is some alternative to repeating the column
              >names in every object.
              >
              > >From: "Matthew Morley" <WickedLogic@...
              ><mailto:WickedLogic%40gmail.com> >
              > >Reply-To: json@yahoogroups.com <mailto:json%40yahoogroups.com>
              > >To: json@yahoogroups.com <mailto:json%40yahoogroups.com>
              > >Subject: Re: [json] json as js variable
              > >Date: Mon, 11 Dec 2006 06:41:03 -0500
              > >
              > >*Identifiers* are names for constants, variables, functions, loop
              >labels,
              > >objects and classes. The first character must be an ASCII letter,
              > >underscore
              > >or dollar sign. Following characters can also include digits.
              > >
              > >Even 'u80020' will do. You can only use numeric indexes if you are
              > >producing
              > >an array.
              > >
              > >--
              > >Matthew P. C. Morley
              > >
              > >
              > >[Non-text portions of this message have been removed]
              > >
              >
              >__________________________________________________________
              >Join the millions of Australians using Live Search. Try live.com.au
              >http://ninemsn.com.au/share/redir/adTrack.asp?mode=click&clientID=740&re
              >ferral=million&URL=http://live.com.au
              ><http://ninemsn.com.au/share/redir/adTrack.asp?mode=click&clientID=740&r
              >eferral=million&URL=http://live.com.au>
              >
              >
              >
              >

              _________________________________________________________________
              Join the millions of Australians using Live Search. Try live.com.au
              http://ninemsn.com.au/share/redir/adTrack.asp?mode=click&clientID=740&referral=million&URL=http://live.com.au
            Your message has been successfully submitted and would be delivered to recipients shortly.