CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript frameworks (http://www.codingforums.com/forumdisplay.php?f=62)
-   -   [jQuery] syntax question (http://www.codingforums.com/showthread.php?t=137087)

edzillion 04-08-2008 10:21 AM

[jQuery] syntax question
 
Hi
Im fairly new to js and find I need to use the jQuery library. I am struggling to understand this code:
Code:

<script id="source" language="javascript" type="text/javascript">
$(function () {
    var datasets = {
        "usa": {
            label: "USA",
            data: [[1988, 483994], [1989, 479060], [1990, 457648], [1991, 401949], [1992, 424705], [1993, 402375], [1994, 377867], [1995, 357382], [1996, 337946], [1997, 336185], [1998, 328611], [1999, 329421], [2000, 342172], [2001, 344932], [2002, 387303], [2003, 440813], [2004, 480451], [2005, 504638], [2006, 528692]]
        },

First off, what is the 'datasets' data structure called?
Secondly, is there a way that I can use a function to populate the 'data' array, like so:
Code:

var datasets = {
    "usa": {
        label: "USA",
        data: xmlToArray('WGTPRICE')
 },

TIA,
Ed

shyam 04-09-2008 10:20 AM

the code is simply constructing a javascript object...all objects in javascript are associative arrays so you can simply add a key-value pair anytime....the notation you see there is called JSON (javascript object notation) which is sorta short form to create objects.

and, yes you can use a function to set the value of an attribute in javascript


All times are GMT +1. The time now is 09:03 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.