【问题标题】:Read stored data with AS3使用 AS3 读取存储的数据
【发布时间】:2015-06-30 05:33:42
【问题描述】:

我想创建一个可以读取和搜索表格的 AIR 应用程序(xml 文件?xls 文件?不知道最简单的)。

示例: 我有一张有 500 行和 6 列的表格。

我想告诉我的 AS3 代码:

If ("date == 6 July" && City == "San Francisco"){
show the hours();

你知道做这种事情的最简单方法吗?


编辑

感谢亚伦的回答。那么,使用 xml,我可以在我的 AS3 代码中做到这一点吗? : 我正在尝试在我的 xml 变量中进行搜索。

例如,我的 AS3 中有

var currentDate=new Date();   
var month=currentDate.getMonth()+1;  
var day=currentDate.getDate();   
var months:Array = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];  
var my_date:Date = new Date();   
var today =(day+" "+ months[my_date.month])  

我正在尝试这样做:

var results:XMLList = myXML.row.(city == "San Francisco" && date == today);  
   if(results.length()){  
   for each(var row:XML in results){  
  trace(row.haute, row.basse, row.haute2, row.basse2);  
   }  

但它不起作用。

我如何以其他工作方式告诉我希望代码搜索 date == today ?

【问题讨论】:

  • 桌子在哪里?
  • 在同一个文件夹中。目前它是一个 xls 文件。
  • @user3094896 当然,使用 XML 文件比使用 XLS 文件更容易。如需搜索,请查看my answer for your other question
  • 对于您的编辑,您需要使用monthmy_date.month + 1。除此之外,它看起来还不错。

标签: database actionscript-3 air


【解决方案1】:

XML 是要走的路。 AS3 支持E4X 语法,允许您轻松查询 XML 对象。

例如,您的 XML 可以这样构造:

<xml>
    <row>
        <date>1 July</date>
        <city>San Francisco</city>
        <hours1>6h50</hours1>
        <hours2>1h14</hours2>
        <hours3>20h01</hours3>
        <hours4>13h16</hours4>
    </row>
</xml>

那么你可以这样查询:

var results:XMLList = myXML.row.(date == "1 July" && city == "San Francisco");
if(results.length()){
    for each(var row:XML in results){
        trace(row.hours1, row.hours2, row.hours3, row.hours4);
    }
}

【讨论】:

  • 超级!有用。在我新编辑的帖子中只有一个问题。如果你知道答案,那就太棒了。
  • 对不起,写得不好。是否可以这样做:日期==今天(我已经编辑了我的帖子)。
  • 是的,这是可能的。您发布的代码看起来是正确的想法。只要确保格式化的日期看起来正确并且有匹配的数据。
  • 是的,你可以在 e4x 表达式中使用局部变量。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-04-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多