Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using XML in Widgets/Javascript



On Jun 23, 2005, at 10:19 PM, David Richmond wrote:

 I am trying to write a widget which uses a static XML file which would be bundled with the widget. I want the XML file to hold the data for items in a popup menu in the widget. So basically when the widget starts it needs to read the xml file to get the options in the menu. I've been trying to figure out how to do this in _javascript_ and have been striking out. 

Since you're abstracting the data out, why not just put it into a _javascript_ file as an array that you iterate through?  Something along this train of thought should work nicely:

You create a file for the values you're abstracting out (say, Values.js).  In it is an array with the needed values:

var Values = [
    "Value 1",
    ...
    "Value n",
];

Then, in your _javascript_ file (say, Widget.js) you include a setup() function that loads the values:

function setup()
{
...
    var menu = document.getElementById("myMenu");
    var c = Values.length;
    
    for ( var i = 0; i < c; i++ ) {
        menu.add(Values[i]);
    }
...
}

To tie it all together you include both _javascript_ files into your HTML and call setup() when your widget's body loads:

<html>
<head>
...
    <script type='text/_javascript_' src='' charset='utf-8'/>
    <script type='text/_javascript_' src='' charset='utf-8'/>
...
</head>
<body >
...
    <select id='myMenu' ></select>
...
</body>
</html>

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Dashboard-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/dashboard-dev/email@hidden

This email sent to email@hidden

References: 
 >Using XML in Widgets/Javascript (From: David Richmond <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.