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

Searching Arrays with numbers

Expand Messages
  • phanthomasx
    Hello, (I was already searching the forum but didn t find any suitable post.) I tried to search for values in an array using has: in Taffy 1.7.2 but it
    Message 1 of 3 , Feb 5, 2010
    • 0 Attachment
      Hello,

      (I was already searching the forum but didn't find any suitable post.)

      I tried to search for values in an array using "has:" in Taffy 1.7.2 but it didn't work with numbers, only strings. :-( Example:

      var friends = new TAFFY(
      [{
        name:"Bob",
        favorite_foods:["pizza","tacos"],
        favorite_numbers:[7,13,99]}
      ])

      resultString = friends.find({favorite_foods:{has:"pizza"}})
      resultNumber = friends.find({favorite_numbers:{has:"99"}})
      resultNumber = friends.find({favorite_numbers:{has:99}})


      "resultString" returns a correct index but both "resultNumber" return nothing. :-( Did I do something wrong in the query or is this a "bug"? (Still, so far, Taffy DB rocks! ;-)

      thanks.

    • tacoman_cool
      I may have to give you a gold star. You found a bug. Looks like I never tested array numbers. I think it is fixable though. Have you found a work around or is
      Message 2 of 3 , Feb 25, 2010
      • 0 Attachment
        I may have to give you a gold star. You found a bug. Looks like I never tested array numbers. I think it is fixable though. Have you found a work around or is it urgent?

        --- In taffydb@yahoogroups.com, phanthomasx <no_reply@...> wrote:
        >
        > Hello,
        >
        > (I was already searching the forum but didn't find any suitable post.)
        >
        > I tried to search for values in an array using "has:" in Taffy 1.7.2 but
        > it didn't work with numbers, only strings. :-( Example:
        >
        > var friends = new TAFFY(
        > [{
        > name:"Bob",
        > favorite_foods:["pizza","tacos"],
        > favorite_numbers:[7,13,99]}
        > ])
        >
        > resultString = friends.find({favorite_foods:{has:"pizza"}})
        > resultNumber = friends.find({favorite_numbers:{has:"99"}})
        > resultNumber = friends.find({favorite_numbers:{has:99}})
        >
        > "resultString" returns a correct index but both "resultNumber" return
        > nothing. :-( Did I do something wrong in the query or is this a "bug"?
        > (Still, so far, Taffy DB rocks! ;-)
        >
        > thanks.
        >
      • phanthomasx
        Hello, thanks for the reply and the golden star. ;-) I created a quite nasty workaround by transforming all numbers into strings but it works. ;-) // read
        Message 3 of 3 , Mar 1, 2010
        • 0 Attachment
          Hello,

          thanks for the reply and the golden star. ;-)
          I created a quite "nasty" workaround by transforming all numbers into strings but it works. ;-)

          // read file using jQuery-library and save in data-object
          $.getJSON("myfile.json", function(data)
             {
                // go through the complete JSON-file/object
                for (i = 0; i<= data.length-1; i++)
                {
                   // if an entry with "favorite_numbers" exists ...
                   if (data[i].favorite_numbers)
                   {
                      // ... go through all the numbers in this array e.g. [7,13,99] or [23,42] ...
                      for (j = 0; j <= data[i].favorite_numbers.length-1; j++)
                      {
                          // ... and transform them from a Number to a String
                           data[i].favorite_numbers[j] = String(data[i].favorite_numbers[j]);
                       }
                   }
                }
                taffyDb = new TAFFY(data);    // global
             });


          --- In taffydb@yahoogroups.com, "tacoman_cool" <ian@...> wrote:
          >
          > I may have to give you a gold star. You found a bug. Looks like I never tested array numbers. I think it is fixable though. Have you found a work around or is it urgent?
          >
          > --- In taffydb@yahoogroups.com, phanthomasx no_reply@ wrote:
          > >
          > > Hello,
          > >
          > > (I was already searching the forum but didn't find any suitable post.)
          > >
          > > I tried to search for values in an array using "has:" in Taffy 1.7.2 but
          > > it didn't work with numbers, only strings. :-( Example:
          > >
          > > var friends = new TAFFY(
          > > [{
          > > name:"Bob",
          > > favorite_foods:["pizza","tacos"],
          > > favorite_numbers:[7,13,99]}
          > > ])
          > >
          > > resultString = friends.find({favorite_foods:{has:"pizza"}})
          > > resultNumber = friends.find({favorite_numbers:{has:"99"}})
          > > resultNumber = friends.find({favorite_numbers:{has:99}})
          > >
          > > "resultString" returns a correct index but both "resultNumber" return
          > > nothing. :-( Did I do something wrong in the query or is this a "bug"?
          > > (Still, so far, Taffy DB rocks! ;-)


        Your message has been successfully submitted and would be delivered to recipients shortly.