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

Confused and frustrated that this isn't working

Expand Messages
  • tiredandweak
    Since the Taffy DB website doesn t give an example of actually retrieving an object at a particular index, I ve been trying for over an hour with little luck.
    Message 1 of 4 , Mar 6, 2010
    • 0 Attachment
      Since the Taffy DB website doesn't give an example of actually retrieving an object at a particular index, I've been trying for over an hour with little luck. Please tell me how I can make this work:

      var db = new TAFFY(
      [
      {
      title:"My Title",
      text:"My Text",
      author:"My Name"
      }
      ]
      );

      var firstMatch = db.find({title:"My Title"})[0];

      alert(db.get(firstMatch).text); //appears as "undefined"
    • tacoman_cool
      You re close. .find() returns an array of indexes for records. .get() returns an array of those records. .first() returns one object (the first returned by a
      Message 2 of 4 , Mar 6, 2010
      • 0 Attachment
        You're close. .find() returns an array of indexes for records. .get() returns an array of those records. .first() returns one object (the first returned by a query).

        So in theory you can do alert(db.first({title:"My Title"}).text)

        --- In taffydb@yahoogroups.com, "tiredandweak" <tiredandweak@...> wrote:
        >
        > Since the Taffy DB website doesn't give an example of actually retrieving an object at a particular index, I've been trying for over an hour with little luck. Please tell me how I can make this work:
        >
        > var db = new TAFFY(
        > [
        > {
        > title:"My Title",
        > text:"My Text",
        > author:"My Name"
        > }
        > ]
        > );
        >
        > var firstMatch = db.find({title:"My Title"})[0];
        >
        > alert(db.get(firstMatch).text); //appears as "undefined"
        >
      • tiredandweak
        That only lets me get the very first match -- I want to be able to get all the records returned by the find() function. After reading your reply, though, I
        Message 3 of 4 , Mar 7, 2010
        • 0 Attachment
          That only lets me get the very first match -- I want to be able to get all the records returned by the find() function. After reading your reply, though, I tried something else that appears to work:

          var db = new TAFFY(
          [
          {
          title:"My Title",
          text:"My Text",
          author:"My Name"
          }
          ]
          );

          alert(db.get(db.find({title:"My Title"}))[0].title);

          I didn't know get() could actually be given the array of indexes returned by find(). Good to know. Thanks!

          --- In taffydb@yahoogroups.com, "tacoman_cool" <ian@...> wrote:
          >
          > You're close. .find() returns an array of indexes for records. .get() returns an array of those records. .first() returns one object (the first returned by a query).
          >
          > So in theory you can do alert(db.first({title:"My Title"}).text)
          >
          > --- In taffydb@yahoogroups.com, "tiredandweak" <tiredandweak@> wrote:
          > >
          > > Since the Taffy DB website doesn't give an example of actually retrieving an object at a particular index, I've been trying for over an hour with little luck. Please tell me how I can make this work:
          > >
          > > var db = new TAFFY(
          > > [
          > > {
          > > title:"My Title",
          > > text:"My Text",
          > > author:"My Name"
          > > }
          > > ]
          > > );
          > >
          > > var firstMatch = db.find({title:"My Title"})[0];
          > >
          > > alert(db.get(firstMatch).text); //appears as "undefined"
          > >
          >
        • tacoman_cool
          Right. .first() is more or less shorthand for .get()[0].
          Message 4 of 4 , Mar 8, 2010
          • 0 Attachment
            Right. .first() is more or less shorthand for .get()[0].

            --- In taffydb@yahoogroups.com, "tiredandweak" <tiredandweak@...> wrote:
            >
            > That only lets me get the very first match -- I want to be able to get all the records returned by the find() function. After reading your reply, though, I tried something else that appears to work:
            >
            > var db = new TAFFY(
            > [
            > {
            > title:"My Title",
            > text:"My Text",
            > author:"My Name"
            > }
            > ]
            > );
            >
            > alert(db.get(db.find({title:"My Title"}))[0].title);
            >
            > I didn't know get() could actually be given the array of indexes returned by find(). Good to know. Thanks!
            >
            > --- In taffydb@yahoogroups.com, "tacoman_cool" <ian@> wrote:
            > >
            > > You're close. .find() returns an array of indexes for records. .get() returns an array of those records. .first() returns one object (the first returned by a query).
            > >
            > > So in theory you can do alert(db.first({title:"My Title"}).text)
            > >
            > > --- In taffydb@yahoogroups.com, "tiredandweak" <tiredandweak@> wrote:
            > > >
            > > > Since the Taffy DB website doesn't give an example of actually retrieving an object at a particular index, I've been trying for over an hour with little luck. Please tell me how I can make this work:
            > > >
            > > > var db = new TAFFY(
            > > > [
            > > > {
            > > > title:"My Title",
            > > > text:"My Text",
            > > > author:"My Name"
            > > > }
            > > > ]
            > > > );
            > > >
            > > > var firstMatch = db.find({title:"My Title"})[0];
            > > >
            > > > alert(db.get(firstMatch).text); //appears as "undefined"
            > > >
            > >
            >
          Your message has been successfully submitted and would be delivered to recipients shortly.