[jQuery] Re: Make list of unique json data?

2008-12-19 Thread alpha tester


Thanks very much for this Brian - got my head round it now!



brian-263 wrote:
> 
> 
> On Thu, Dec 18, 2008 at 4:49 AM, alpha tester 
> wrote:
>>
>>
>> Hmmm...  struggling to read from this new dataset using the code provided
>> -
>> can someone point out the stupidity in the following code:
>>
>> 
>> 
>> 
>> var myData =
>> { records : [
>> { CATEGORY : "Sport", TITLE : "The world of sport", LINK:
>> "<a  rel="nofollow" href="http://test.com"">http://test.com"</a>;
>> },
>> { CATEGORY : "Sport", TITLE : "More sport", LINK: "<a  rel="nofollow" href="http://test.com"">http://test.com"</a>; },
>> { CATEGORY : "News", TITLE : "News views", LINK: "<a  rel="nofollow" href="http://test.com"">http://test.com"</a>; },
>> { CATEGORY : "News", TITLE : "Some more news", LINK: "<a  rel="nofollow" href="http://test.com"">http://test.com"</a>; },
>> { CATEGORY : "Events", TITLE : "Big Events", LINK: "<a  rel="nofollow" href="http://test.com"">http://test.com"</a>; },
>> { CATEGORY : "Events", TITLE : "Small Events", LINK: "<a  rel="nofollow" href="http://test.com"">http://test.com"</a>; },
>> ]};
>> 
>> 
>> 
>> 
>> 
>> 
>> test
>> 
>> 
>>
>> 

[jQuery] Re: Make list of unique json data?

2008-12-18 Thread alpha tester


Hmmm...  struggling to read from this new dataset using the code provided -
can someone point out the stupidity in the following code:




var myData = 
{ records : [ 
{ CATEGORY : "Sport", TITLE : "The world of sport", LINK: "http://test.com";
}, 
{ CATEGORY : "Sport", TITLE : "More sport", LINK: "http://test.com"; }, 
{ CATEGORY : "News", TITLE : "News views", LINK: "http://test.com"; }, 
{ CATEGORY : "News", TITLE : "Some more news", LINK: "http://test.com"; }, 
{ CATEGORY : "Events", TITLE : "Big Events", LINK: "http://test.com"; }, 
{ CATEGORY : "Events", TITLE : "Small Events", LINK: "http://test.com"; }, 
]};






test





// Group categories dynamically into datasets
var categories = {}, groupBy = "CATEGORY"; 
$.each(myData.records, function(i, record) 
{ 
  if (!categories[record[groupBy]]) 
 categories[record[groupBy]] = []; 
  categories[record[groupBy]].push(record);
});

//total number of categories
var categoryCount = myData.records.length-1;

// Append categories to unordered list item
for (i=0;i<=categoryCount;i++)
{
$("ul").append("
  • "+categories.records[i].CATEGORY+"
  • "); } -- View this message in context: http://www.nabble.com/Make-%3Cli%3E-list-of-unique-json-data--tp21054524s27240p21069670.html Sent from the jQuery General Discussion mailing list archive at Nabble.com.

    [jQuery] Re: Make list of unique json data?

    2008-12-18 Thread alpha tester
    
    
    Amazing! Love the way you can take what was about 90 lines of javascript and
    turn it into about 5 of jquery and the jquery ends up being far more
    flexible!
    
    Thanks very much for your help!
    
    (do you know of any tutorials that cover this sort of dataset management
    stuff (push/group etc))
    
    
    brian-263 wrote:
    > 
    > 
    > On Wed, Dec 17, 2008 at 7:27 PM, Dave Methvin 
    > wrote:
    >>
    >> It might be worthwhile to generalize it and just push the original
    >> JSON record onto the list. That way the code doesn't need to change if
    >> you later need to pass more than title and link.
    >>
    >> var categories = {}, groupBy = "CATEGORY";
    >> $.each(myData.records, function(i, record)
    >> {
    >>   if (!categories[record[groupBy]])
    >>  categories[record[groupBy]] = [];
    >>   categories[record[groupBy]].push(record);
    >> });
    >>
    > 
    > Good tip!
    > 
    > 
    
    -- 
    View this message in context: 
    http://www.nabble.com/Make-%3Cli%3E-list-of-unique-json-data--tp21054524s27240p21068618.html
    Sent from the jQuery General Discussion mailing list archive at Nabble.com.
    
    
    

    [jQuery] Make list of unique json data?

    2008-12-17 Thread alpha tester
    
    
    Hi I'm just learning JQuery and while I've got my head around the general
    concepts, the real power of the logic it provides is still escaping me.
    
    I've got a page with a JSON dataset like this:
    
    var myData = 
    { records : [ 
    { CATEGORY : "Sport", TITLE : "The world of sport", LINK: "http://test.com";
    }, 
    { CATEGORY : "Sport", TITLE : "More sport", LINK: "http://test.com"; },
    { CATEGORY : "News", TITLE : "News views", LINK: "http://test.com"; },
    { CATEGORY : "News", TITLE : "Some more news", LINK: "http://test.com"; },
    { CATEGORY : "Events", TITLE : "Big Events", LINK: "http://test.com"; },
    { CATEGORY : "Events", TITLE : "Small Events", LINK: "http://test.com"; },
    ]}
    
    Now this is being built into a nested list using Jquery, however at the
    moment I'm hardcoding the category names in my script and looping through
    each title.
    
    I'm now hitting increasing issues as if categories are added/removed it
    become a chore to update.
    
    Can anyone tell me if it's possible to automatically generate a list of
    unique categories?
    
    ie so it'd produce this:
    
    
    Sport
    News
    Events
    
    
    Not:
    
    Sport
    Sport
    News
    News
    Events
    Events
    
    
    -- 
    View this message in context: 
    http://www.nabble.com/Make-%3Cli%3E-list-of-unique-json-data--tp21054524s27240p21054524.html
    Sent from the jQuery General Discussion mailing list archive at Nabble.com.