如何获取读取数据的视图 [英] How to get a view to read data

查看:18
本文介绍了如何获取读取数据的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的专业需要转换很多东西 - 所以我正在为我的手机构建一个转换工具,其中一些转换是我经常使用的.

I need to convert a lot of stuff in my profession - so I'm building a conversion tool for my phone with some of the conversions I use a lot.

现在,我希望能够正确地构建它.到目前为止,这是我的代码:

Now, I want to be able to build this properly. So far, here's my code:

    <s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" title="Length">

<fx:Script>
    <![CDATA[
        protected function button1_clickHandler(event:MouseEvent):void
        {
            var Result:String;
            var Finish:Number;
            var Start:Number = parseFloat(Input.text);
            Finish = Start * convert.selectedItem.data; 
            Result = String(Finish);
            answer.text = Result;

        }
    ]]>
</fx:Script>

<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>




<s:TextInput id="Input" x="20" y="46"/>
<s:SpinnerListContainer x="140" y="122" width="200" height="200">
    <s:SpinnerList id="convert" height="100%" width="100%" labelField="label" selectedIndex="1">
        <s:ArrayList>
            <fx:Object label="km to mi" data="0.62137119224"></fx:Object>
            <fx:Object label="km to yd" data="1093.6132983 "></fx:Object>
            <fx:Object label="km to ft" data="3280.839895"></fx:Object>
            <fx:Object label="km to in" data="39370.07874"></fx:Object>
            <fx:Object label="km to m" data="1000"></fx:Object>
            <fx:Object label="km to cm" data="100000"></fx:Object>
            <fx:Object label="km to mm" data="1000000"></fx:Object>

    </s:ArrayList>
            </s:SpinnerList>
        </s:SpinnerListContainer>
        <s:Label id="answer" x="66" y="533" width="348" text="Answer"/>
        <s:Button x="66" y="377" width="338"           click="button1_clickHandler(event)" label="Button"/>

    </View>

正如你所看到的,我会遇到一些问题:

As you can see, I'm going to run into some problems with this:

1) 一切都是硬编码的,如果我想添加、删除或更改数组中的元素,会有点麻烦.

1) Everything is hard-coded, and if I want to add, remove or change the elements in the array, it's going to be a bit of a pain.

2) 对于我的体积和重量转换,我有一个基本相同的视图.遇到同样的问题.

2) I have a view that is essentially the same for my volume and weight conversions. With the same problem.

我想做什么,但我在理解时遇到了一些麻烦,就是将所有硬编码的东西放在一个地方,并让相同的视图根据我之前的视图显示它,这只是一个简单的、困难的-编码列表.

What I'd like to do, but I'm having some trouble understanding, is getting all that hard-coded stuff in one place and having the same view show it based on my previous view which is just a plain, hard-coded list.

我正在考虑像 xml 表之类的东西,并向对象添加 category = "length"category = "weight" 元素,以便我可以在列表中显示 xml 中的类别,然后当我单击长度"时,它会从此列表中读取标签 + 数据.这是一个很好的解决方案吗?以及如何让 selectedItem 记住应该从 xml 列表的哪一部分填充视图?

I'm thinking of something like an xml sheet, and adding a category = "length" or category = "weight" element to the objects, so that I can show the category from the xml in the List, then when I click "length" it reads the label + data from this list. Is that a good solution? And how exactly do I get the selectedItem to remember which part of the xml list the view should be populated from?

有几个xml文件会更好吗?但这仍然意味着我必须在需要时更新一大堆地方.

Would it be better to have several xml files? But that still would mean I have to update a whole bunch of places when I need it.

基本上,我需要以下方面的帮助:

Basically, I need assistance with:

所以 - 现在的问题有两个:

So - Now the question is two-fold:

1) 如何在多个视图之间保持与 xml/db 的连接?

1) How to keep a connection to xml/db open across multiple views?

2) 如何根据数据库中的信息填充端视图?

2) How to populate the end-view from information from the db?

感谢您的建议和帮助.

推荐答案

您是否考虑过使用资源包?还是 LSO?

Have you looked at using resource bundles? Or LSOs?

在持久化 Flex 数据时,您有 4 个主要选项.

When persisting Flex data, you have 4 main options.

  1. 关系数据库(这里似乎有点矫枉过正)
  2. XML(您似乎已经习惯了)
  3. 资源包
  4. 本地共享对象

上面链接的 LSO 示例 (#4) 为您的问题提供了一个潜在的解决方案:

The LSO example, linked above (#4), gives a potential solution to your question:

...我究竟如何让 selectedItem 记住应该从 xml 列表的哪一部分填充视图?

... how exactly do I get the selectedItem to remember which part of the xml list the view should be populated from?

片段:

public function initApp():void {
    mySO = SharedObject.getLocal("mydata");
    if (mySO.data.visitDate==null) {
       welcomeMessage = "Hello first-timer!"
    } else {
       welcomeMessage = "Welcome back. You last visited on " +
          getVisitDate();
    }
 }

private function getVisitDate():Date {
   return mySO.data.visitDate;
}

private function storeDate():void {
   mySO.data.visitDate = new Date();
   mySO.flush();
}

private function deleteLSO():void {
   // Deletes the SharedObject from the client machine.
   // Next time they log in, they will be a 'first-timer'.
   mySO.clear();
}

我建议使用 XML 和 LSO 或资源包和 LSO 的组合——其中您的 XML/RB 存储不变的静态数据,而您的 LSO 跟踪动态数据(视图设置等).

I'd recommend using either a combination of XML and LSOs or resource bundles and LSOs--where your XML/RB stores non-changing, static data and your LSO keeps track of dynamic data (view settings, etc).

这篇关于如何获取读取数据的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆