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

stringify

Expand Messages
  • Rory Barrett
    Hello fellow Taffy Users I have only just begun using Taffy and have encountered a problem that someone can possibly help with. Suppose you have a collection
    Message 1 of 7 , Dec 20, 2009
    • 0 Attachment
      Hello fellow Taffy Users
       
      I have only just begun using Taffy and have encountered a problem that someone can possibly help with.
       
      Suppose you have a collection consisting of 5 records called coll. Each record has 4 fields say F1,F2,F3, F4.
       
      If I declare an array called myColl = coll.stringify();
      do I get a string array myColl so if I use myColl[3][2]  I get a string which is the string version of the second field of the third record ?
       
      I have assumed this to be the case but have been informed by the page I have been working on there are errors.
       
      I really need the string version of the second field of the third record and similar. If I can't get it using stringify then how do I do so and how does stringify() work ?
       
      Rory Barrett
    • tacoman_cool
      Hi Rory, Let s back up a second. If you have some data you can create a Taffy collection as follows: var mycollection = TAFFY([
      Message 2 of 7 , Dec 20, 2009
      • 0 Attachment
        Hi Rory,

        Let's back up a second. If you have some data you can create a Taffy collection as follows:

        var mycollection = TAFFY([
        [{F1:"Amy",F2:"Palmer"},{F1:""Bob",F2:"Smith"}]
        ])

        Now you can do a lot.

        mycollection.stringify() will turn all your data into a JSON packet that you can print to the string, pass back to the server, etc. Example:

        alert(mycollection.stringify());

        If you want just the first record you can get it like this:

        mycollection.first();

        This returns the record itself. So this should alert "Amy":

        alert(mycollection.first().F1);

        If you want the first record where F2 is "Smith" you can do this. It will alert Bob:

        alert(mycollection.first({F2:"Smith"}).F1);

        I hope that helps,

        Ian

        --- In taffydb@yahoogroups.com, "Rory Barrett" <ramses@...> wrote:
        >
        > Hello fellow Taffy Users
        >
        > I have only just begun using Taffy and have encountered a problem that someone can possibly help with.
        >
        > Suppose you have a collection consisting of 5 records called coll. Each record has 4 fields say F1,F2,F3, F4.
        >
        > If I declare an array called myColl = coll.stringify();
        > do I get a string array myColl so if I use myColl[3][2] I get a string which is the string version of the second field of the third record ?
        >
        > I have assumed this to be the case but have been informed by the page I have been working on there are errors.
        >
        > I really need the string version of the second field of the third record and similar. If I can't get it using stringify then how do I do so and how does stringify() work ?
        >
        > Rory Barrett
        >
      • Rory Barrett
        Hello Ian coudn t help myself so am giving you this before I go to the gym. I took a previous script and introduced taffy into it until I had an error.I have
        Message 3 of 7 , Dec 20, 2009
        • 0 Attachment
          Hello Ian
           
           coudn't help myself so am giving you this before I go to the gym.
           
          I took a previous script and introduced taffy into it until I had an error.I have commented where the code is that's producing the error. There may be other bits. What is wqrong. I tried what you suggested bur to no avail. Help !
           
          Rory
           
          <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
          <html>
          <head>
           
          <script type="text/javascript" src="taffy.js "></script>
           
          <script type="text/javascript">
           
          var numFriends=4;
           
           
           
           
           
          var friends = new TAFFY(
          [
          {firstName:"Bob",
            familyName:"Marley"},
          {firstName:"Bill",
            familyName:"Marlin"},
           {firstName:"Bud",
            familyName:"Weiser"},
           {firstName:"Bad",
            familyName:"Ass"}
            ]
          )
           
          myFriends = friends.stringify();
           
          function insRows(){
          var orows = document.getElementById('myTable').getElementsByTagName('tr');
          var rowCount = orows.length;
           
          if (rowCount< numFriends) {
           for(qNum=1;qNum<=numFriends;qNum++)
           {
             
              var x=document.getElementById('myTable').insertRow(myTable.rows.length);
              var y=x.insertCell(0);
              var z=x.insertCell(1);
                y.align = 'center';
              z.align = 'left';
           
              y.innerHTML= "hank" ;
              z.innerHTML="spank";
           
           
           

            
           
           
             
            }//end of for
           }//end of if
          }//end insRows
           
           
           

          </script>
           
           
           

          </head>
           

          <body onload= "insRows();">
           
          <table id="bigTable" width = "80%" border="1">
           
          <tr align='center'>
            <td width = "10%">
           
               <table id="myTable" width = "80%" border="1">
           
                  <tr align='center'>
                  <td width = "10%">Question Number</td>
                  <td width = "40%">Actual Question</td>
                 <!-- <td width = "10%">Answer</td>
                  <td width = "5%">Right/Wrong</td> //Dec20 -->
                  </tr>
           
               </table>
           

             </td>
           
            </tr>
           
          </table>
           
          <script type="text/javascript">
          <!-- Here is the simple command that seems to causing problems-->

          document.write(myFriends.first().firstName);
          <!----------->
          </script>
           
          </body>
          </html>
          ----- Original Message -----
          Sent: Monday, December 21, 2009 4:50 PM
          Subject: [taffydb] Re: stringify

           

          Hi Rory,

          Let's back up a second. If you have some data you can create a Taffy collection as follows:

          var mycollection = TAFFY([
          [{F1:"Amy",F2: "Palmer"} ,{F1:""Bob" ,F2:"Smith" }]
          ])

          Now you can do a lot.

          mycollection. stringify( ) will turn all your data into a JSON packet that you can print to the string, pass back to the server, etc. Example:

          alert(mycollection. stringify( ));

          If you want just the first record you can get it like this:

          mycollection. first();

          This returns the record itself. So this should alert "Amy":

          alert(mycollection. first().F1) ;

          If you want the first record where F2 is "Smith" you can do this. It will alert Bob:

          alert(mycollection. first({F2: "Smith"}) .F1);

          I hope that helps,

          Ian

          --- In taffydb@yahoogroups .com, "Rory Barrett" <ramses@...> wrote:
          >
          > Hello fellow Taffy Users
          >
          > I have only just begun using Taffy and have encountered a problem that someone can possibly help with.
          >
          > Suppose you have a collection consisting of 5 records called coll. Each record has 4 fields say F1,F2,F3, F4.
          >
          > If I declare an array called myColl = coll.stringify( );
          > do I get a string array myColl so if I use myColl[3][2] I get a string which is the string version of the second field of the third record ?
          >
          > I have assumed this to be the case but have been informed by the page I have been working on there are errors.
          >
          > I really need the string version of the second field of the third record and similar. If I can't get it using stringify then how do I do so and how does stringify() work ?
          >
          > Rory Barrett
          >

        • Rory Barrett
          Hello Colleagues I am not familar with JSON. If I need it then I will learn about it. Right now all I want to be able to do is be able to turn the different
          Message 4 of 7 , Dec 21, 2009
          • 0 Attachment
            Hello Colleagues
             
            I am not  familar with JSON. If I need it then I will learn about it. Right now all I want to be able to do is be able to turn the different fields in the records in a collection into strings which can be used in a javascript program.
             
            What I mean is this. Assuming you had a really simple collection like
            var mycollection = TAFFY([
            [{F1:"Amy",F2: "Palmer"} ,{F1:""Bob" ,F2:"Smith" }]
            ])
            and suppose you needed the F2s as strings then how do you get this ?
             
            I am sorry to ask questions about something that probably seems really basic and pointless however if Taffy offers a way of getting persistence simply then all my computing problems are solved.
             
            My current situation is that I have very good javascript programs that generate values as strings. The problem is that when I turn the computerr off these values cease to exist. What I need is for them to be retained. I thought that Taffy was a way I could do this. I expect that it is but I need to be able to turn records into arrays of strings which can be used in a javascript program. Is anyone able to help without referring to JSON which I know little about and seems somewhat complicated.
             
            Rory Barrett

            ----- Original Message -----
            Sent: Monday, December 21, 2009 4:50 PM
            Subject: [taffydb] Re: stringify

             

            Hi Rory,

            Let's back up a second. If you have some data you can create a Taffy collection as follows:

            var mycollection = TAFFY([
            [{F1:"Amy",F2: "Palmer"} ,{F1:""Bob" ,F2:"Smith" }]
            ])

            Now you can do a lot.

            mycollection. stringify( ) will turn all your data into a JSON packet that you can print to the string, pass back to the server, etc. Example:

            alert(mycollection. stringify( ));

            If you want just the first record you can get it like this:

            mycollection. first();

            This returns the record itself. So this should alert "Amy":

            alert(mycollection. first().F1) ;

            If you want the first record where F2 is "Smith" you can do this. It will alert Bob:

            alert(mycollection. first({F2: "Smith"}) .F1);

            I hope that helps,

            Ian

            --- In taffydb@yahoogroups .com, "Rory Barrett" <ramses@...> wrote:
            >
            > Hello fellow Taffy Users
            >
            > I have only just begun using Taffy and have encountered a problem that someone can possibly help with.
            >
            > Suppose you have a collection consisting of 5 records called coll. Each record has 4 fields say F1,F2,F3, F4.
            >
            > If I declare an array called myColl = coll.stringify( );
            > do I get a string array myColl so if I use myColl[3][2] I get a string which is the string version of the second field of the third record ?
            >
            > I have assumed this to be the case but have been informed by the page I have been working on there are errors.
            >
            > I really need the string version of the second field of the third record and similar. If I can't get it using stringify then how do I do so and how does stringify() work ?
            >
            > Rory Barrett
            >

          • tacoman_cool
            Hi Rory, I think I see your problem. You re setting: myFriends = friends.stringify() And then trying to do this: document.write(myFriends.first().firstName);
            Message 5 of 7 , Dec 21, 2009
            • 0 Attachment
              Hi Rory,

              I think I see your problem. You're setting:

              myFriends = friends.stringify()

              And then trying to do this:

              document.write(myFriends.first().firstName);

              But myFriends is a string now, not a Taffy Object. friends.first().firstName should work.

              Ian

              --- In taffydb@yahoogroups.com, "Rory Barrett" <ramses@...> wrote:
              >
              > Hello Ian
              >
              > coudn't help myself so am giving you this before I go to the gym.
              >
              > I took a previous script and introduced taffy into it until I had an error.I have commented where the code is that's producing the error. There may be other bits. What is wqrong. I tried what you suggested bur to no avail. Help !
              >
              > Rory
              >
              > <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
              > <html>
              > <head>
              >
              > <script type="text/javascript" src="taffy.js "></script>
              >
              > <script type="text/javascript">
              >
              > var numFriends=4;
              >
              >
              >
              >
              >
              > var friends = new TAFFY(
              > [
              > {firstName:"Bob",
              > familyName:"Marley"},
              > {firstName:"Bill",
              > familyName:"Marlin"},
              > {firstName:"Bud",
              > familyName:"Weiser"},
              > {firstName:"Bad",
              > familyName:"Ass"}
              > ]
              > )
              >
              > myFriends = friends.stringify();
              >
              > function insRows(){
              > var orows = document.getElementById('myTable').getElementsByTagName('tr');
              > var rowCount = orows.length;
              >
              > if (rowCount< numFriends) {
              > for(qNum=1;qNum<=numFriends;qNum++)
              > {
              >
              > var x=document.getElementById('myTable').insertRow(myTable.rows.length);
              > var y=x.insertCell(0);
              > var z=x.insertCell(1);
              > y.align = 'center';
              > z.align = 'left';
              >
              > y.innerHTML= "hank" ;
              > z.innerHTML="spank";
              >
              >
              >
              >
              >
              >
              >
              >
              > }//end of for
              > }//end of if
              > }//end insRows
              >
              >
              >
              >
              > </script>
              >
              >
              >
              >
              > </head>
              >
              >
              > <body onload= "insRows();">
              >
              > <table id="bigTable" width = "80%" border="1">
              >
              > <tr align='center'>
              > <td width = "10%">
              >
              > <table id="myTable" width = "80%" border="1">
              >
              > <tr align='center'>
              > <td width = "10%">Question Number</td>
              > <td width = "40%">Actual Question</td>
              > <!-- <td width = "10%">Answer</td>
              > <td width = "5%">Right/Wrong</td> //Dec20 -->
              > </tr>
              >
              > </table>
              >
              >
              > </td>
              >
              > </tr>
              >
              > </table>
              >
              > <script type="text/javascript">
              > <!-- Here is the simple command that seems to causing problems-->
              >
              > document.write(myFriends.first().firstName);
              > <!----------->
              > </script>
              >
              > </body>
              > </html>
              >
              > ----- Original Message -----
              > From: tacoman_cool
              > To: taffydb@yahoogroups.com
              > Sent: Monday, December 21, 2009 4:50 PM
              > Subject: [taffydb] Re: stringify
              >
              >
              >
              > Hi Rory,
              >
              > Let's back up a second. If you have some data you can create a Taffy collection as follows:
              >
              > var mycollection = TAFFY([
              > [{F1:"Amy",F2:"Palmer"},{F1:""Bob",F2:"Smith"}]
              > ])
              >
              > Now you can do a lot.
              >
              > mycollection.stringify() will turn all your data into a JSON packet that you can print to the string, pass back to the server, etc. Example:
              >
              > alert(mycollection.stringify());
              >
              > If you want just the first record you can get it like this:
              >
              > mycollection.first();
              >
              > This returns the record itself. So this should alert "Amy":
              >
              > alert(mycollection.first().F1);
              >
              > If you want the first record where F2 is "Smith" you can do this. It will alert Bob:
              >
              > alert(mycollection.first({F2:"Smith"}).F1);
              >
              > I hope that helps,
              >
              > Ian
              >
              > --- In taffydb@yahoogroups.com, "Rory Barrett" <ramses@> wrote:
              > >
              > > Hello fellow Taffy Users
              > >
              > > I have only just begun using Taffy and have encountered a problem that someone can possibly help with.
              > >
              > > Suppose you have a collection consisting of 5 records called coll. Each record has 4 fields say F1,F2,F3, F4.
              > >
              > > If I declare an array called myColl = coll.stringify();
              > > do I get a string array myColl so if I use myColl[3][2] I get a string which is the string version of the second field of the third record ?
              > >
              > > I have assumed this to be the case but have been informed by the page I have been working on there are errors.
              > >
              > > I really need the string version of the second field of the third record and similar. If I can't get it using stringify then how do I do so and how does stringify() work ?
              > >
              > > Rory Barrett
              > >
              >
            • Rory Barrett
              Hello Ian Deadright. I did what you suggested. It worked brilliantly. I commented out document.write(friends.first().firstName); and substituted
              Message 6 of 7 , Dec 21, 2009
              • 0 Attachment
                Hello Ian
                 
                Deadright. I did what you suggested. It worked brilliantly. I commented out document.write(friends.first().firstName); and substituted document.write(fmyFiends.); This time the entire collection was printed. I then tried document.write(friends.get()[2].firstName); To my delight the first name of the second record was printed. I am now going to dry inserting a new record or two and see what happens.
                 
                As a matter of interest how many records are possible if they each have about 25 fields ?
                 
                Rory
                ----- Original Message -----
                Sent: Tuesday, December 22, 2009 6:07 AM
                Subject: [taffydb] Re: stringify

                 

                Hi Rory,

                I think I see your problem. You're setting:

                myFriends = friends.stringify( )

                And then trying to do this:

                document.write( myFriends. first().firstNam e);

                But myFriends is a string now, not a Taffy Object. friends.first( ).firstName should work.

                Ian

                --- In taffydb@yahoogroups .com, "Rory Barrett" <ramses@...> wrote:
                >
                > Hello Ian
                >
                > coudn't help myself so am giving you this before I go to the gym.
                >
                > I took a previous script and introduced taffy into it until I had an error.I have commented where the code is that's producing the error. There may be other bits. What is wqrong. I tried what you suggested bur to no avail. Help !
                >
                > Rory
                >
                > <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional/ /EN">
                > <html>
                > <head>
                >
                > <script type="text/javascri pt" src="taffy.js "></script>
                >
                > <script type="text/javascri pt">
                >
                > var numFriends=4;
                >
                >
                >
                >
                >
                > var friends = new TAFFY(
                > [
                > {firstName:" Bob",
                > familyName:" Marley"},
                > {firstName:" Bill",
                > familyName:" Marlin"},
                > {firstName:" Bud",
                > familyName:" Weiser"},
                > {firstName:" Bad",
                > familyName:" Ass"}
                > ]
                > )
                >
                > myFriends = friends.stringify( );
                >
                > function insRows(){
                > var orows = document.getElement ById('myTable' ).getElementsByT agName('tr' );
                > var rowCount = orows.length;
                >
                > if (rowCount< numFriends) {
                > for(qNum=1;qNum< =numFriends; qNum++)
                > {
                >
                > var x=document.getEleme ntById('myTable' ).insertRow( myTable.rows. length);
                > var y=x.insertCell( 0);
                > var z=x.insertCell( 1);
                > y.align = 'center';
                > z.align = 'left';
                >
                > y.innerHTML= "hank" ;
                > z.innerHTML= "spank";
                >
                >
                >
                >
                >
                >
                >
                >
                > }//end of for
                > }//end of if
                > }//end insRows
                >
                >
                >
                >
                > </script>
                >
                >
                >
                >
                > </head>
                >
                >
                > <body onload= "insRows();" >
                >
                > <table id="bigTable" width = "80%" border="1">
                >
                > <tr align='center' >
                > <td width = "10%">
                >
                > <table id="myTable" width = "80%" border="1">
                >
                > <tr align='center' >
                > <td width = "10%">Question Number</td>
                > <td width = "40%">Actual Question</td>
                > <!-- <td width = "10%">Answer< /td>
                > <td width = "5%">Right/Wrong< /td> //Dec20 -->
                > </tr>
                >
                > </table>
                >
                >
                > </td>
                >
                > </tr>
                >
                > </table>
                >
                > <script type="text/javascri pt">
                > <!-- Here is the simple command that seems to causing problems-->
                >
                > document.write( myFriends. first().firstNam e);
                > <!---------- ->
                > </script>
                >
                > </body>
                > </html>
                >
                > ----- Original Message -----
                > From: tacoman_cool
                > To: taffydb@yahoogroups .com
                > Sent: Monday, December 21, 2009 4:50 PM
                > Subject: [taffydb] Re: stringify
                >
                >
                >
                > Hi Rory,
                >
                > Let's back up a second. If you have some data you can create a Taffy collection as follows:
                >
                > var mycollection = TAFFY([
                > [{F1:"Amy",F2: "Palmer"} ,{F1:""Bob" ,F2:"Smith" }]
                > ])
                >
                > Now you can do a lot.
                >
                > mycollection. stringify( ) will turn all your data into a JSON packet that you can print to the string, pass back to the server, etc. Example:
                >
                > alert(mycollection. stringify( ));
                >
                > If you want just the first record you can get it like this:
                >
                > mycollection. first();
                >
                > This returns the record itself. So this should alert "Amy":
                >
                > alert(mycollection. first().F1) ;
                >
                > If you want the first record where F2 is "Smith" you can do this. It will alert Bob:
                >
                > alert(mycollection. first({F2: "Smith"}) .F1);
                >
                > I hope that helps,
                >
                > Ian
                >
                > --- In taffydb@yahoogroups .com, "Rory Barrett" <ramses@> wrote:
                > >
                > > Hello fellow Taffy Users
                > >
                > > I have only just begun using Taffy and have encountered a problem that someone can possibly help with.
                > >
                > > Suppose you have a collection consisting of 5 records called coll. Each record has 4 fields say F1,F2,F3, F4.
                > >
                > > If I declare an array called myColl = coll.stringify( );
                > > do I get a string array myColl so if I use myColl[3][2] I get a string which is the string version of the second field of the third record ?
                > >
                > > I have assumed this to be the case but have been informed by the page I have been working on there are errors.
                > >
                > > I really need the string version of the second field of the third record and similar. If I can't get it using stringify then how do I do so and how does stringify() work ?
                > >
                > > Rory Barrett
                > >
                >

              • tacoman_cool
                You ve hit the nail on the head :-) You can t persist values in JavaScript without either using browser features (somewhat iffy) or having a server somewhere
                Message 7 of 7 , Dec 21, 2009
                • 0 Attachment
                  You've hit the nail on the head :-) You can't persist values in JavaScript without either using browser features (somewhat iffy) or having a server somewhere to pass data to and have that data written to a database.

                  For a server you'll be using Ajax, for trying to save data to the browser I can reccomend playing around with http://pablotron.org/software/persist-js/

                  As a side note, there is no limit on size of objects or number of records. However once you get over 4 or 5 thousands records things start to slow down depending on how you use Taffy. I have seen collections as big as 50K though.

                  --- In taffydb@yahoogroups.com, "Rory Barrett" <ramses@...> wrote:
                  >
                  > Hello Colleagues
                  >
                  > I am not familar with JSON. If I need it then I will learn about it. Right now all I want to be able to do is be able to turn the different fields in the records in a collection into strings which can be used in a javascript program.
                  >
                  > What I mean is this. Assuming you had a really simple collection like
                  > var mycollection = TAFFY([
                  > [{F1:"Amy",F2:"Palmer"},{F1:""Bob",F2:"Smith"}]
                  > ])
                  > and suppose you needed the F2s as strings then how do you get this ?
                  >
                  > I am sorry to ask questions about something that probably seems really basic and pointless however if Taffy offers a way of getting persistence simply then all my computing problems are solved.
                  >
                  > My current situation is that I have very good javascript programs that generate values as strings. The problem is that when I turn the computerr off these values cease to exist. What I need is for them to be retained. I thought that Taffy was a way I could do this. I expect that it is but I need to be able to turn records into arrays of strings which can be used in a javascript program. Is anyone able to help without referring to JSON which I know little about and seems somewhat complicated.
                  >
                  > Rory Barrett
                  >
                  >
                  > ----- Original Message -----
                  > From: tacoman_cool
                  > To: taffydb@yahoogroups.com
                  > Sent: Monday, December 21, 2009 4:50 PM
                  > Subject: [taffydb] Re: stringify
                  >
                  >
                  >
                  > Hi Rory,
                  >
                  > Let's back up a second. If you have some data you can create a Taffy collection as follows:
                  >
                  > var mycollection = TAFFY([
                  > [{F1:"Amy",F2:"Palmer"},{F1:""Bob",F2:"Smith"}]
                  > ])
                  >
                  > Now you can do a lot.
                  >
                  > mycollection.stringify() will turn all your data into a JSON packet that you can print to the string, pass back to the server, etc. Example:
                  >
                  > alert(mycollection.stringify());
                  >
                  > If you want just the first record you can get it like this:
                  >
                  > mycollection.first();
                  >
                  > This returns the record itself. So this should alert "Amy":
                  >
                  > alert(mycollection.first().F1);
                  >
                  > If you want the first record where F2 is "Smith" you can do this. It will alert Bob:
                  >
                  > alert(mycollection.first({F2:"Smith"}).F1);
                  >
                  > I hope that helps,
                  >
                  > Ian
                  >
                  > --- In taffydb@yahoogroups.com, "Rory Barrett" <ramses@> wrote:
                  > >
                  > > Hello fellow Taffy Users
                  > >
                  > > I have only just begun using Taffy and have encountered a problem that someone can possibly help with.
                  > >
                  > > Suppose you have a collection consisting of 5 records called coll. Each record has 4 fields say F1,F2,F3, F4.
                  > >
                  > > If I declare an array called myColl = coll.stringify();
                  > > do I get a string array myColl so if I use myColl[3][2] I get a string which is the string version of the second field of the third record ?
                  > >
                  > > I have assumed this to be the case but have been informed by the page I have been working on there are errors.
                  > >
                  > > I really need the string version of the second field of the third record and similar. If I can't get it using stringify then how do I do so and how does stringify() work ?
                  > >
                  > > Rory Barrett
                  > >
                  >
                Your message has been successfully submitted and would be delivered to recipients shortly.