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

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

问题描述

我需要转换很多专业知识-因此,我正在为手机构建转换工具,其中包含一些我经常使用的转换.

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. 本地共享对象
  1. Relational Databases (seems like overkill here)
  2. XML (which you already seem comfortable with)
  3. Resource Bundles
  4. Local Shared Objects

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

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天全站免登陆