这是我的问题。如何将变量与数组中的条目进行比较
我正在做闪存中的一个小天气的web应用程序。 所以我读了一个XML feed,并从中复制了一组数据。
我的XML是这样
<xml>
<prevision>
<date>22</date>
<hour>5</hour>
<temperature>40</temperature>
</prevision>
<prevision>
<date>22</date>
<hour>10</hour>
<temperature>44</temperature>
</prevision>
<prevision>
<date>22</date>
<hour>14</hour>
<temperature>45</temperature>
</prevision>
<prevision>
<date>22</date>
<hour>20</hour>
<temperature>37</temperature>
</prevision>
</xml>
所以这里就是我和我的Actionscript做现在2
//**************************************
// Here i'm getting the current hour
var mytime = new Date();
var currenthour = mytime.getHours();
//*************************************
// Here i'm getting my XML
var myhour:Array = new Array();
var myxml:XML = new XML();
myxml.ignoreWhite = true;
myxml.onLoad = function(success)
{
dataextractor = myxml.firstChild.childNodes;
for (var j = 0; j < dataextractor.length; j++)
{
myhour.push(dataextractor[j].childNodes[1].firstChild.nodeValue);
}
// Doing this
trace(mydate);
}
// Will return this
// 5 , 10, 14 , 20
我想要做什么是寻找和追踪在入境mydate数组,它的值最接近“currenthour”变量(这是我当前上升的时间)。
对于为例如果currentHour的= 11 当i具有myhour阵列等于5,10,14,20 最佳匹配将是如此myhour [1]
有人帮助可以这样做呢? myhour数组没有固定数量的条目。 有时也可以是5,10,14和其他时间只是14,20等
非常感谢,