简体   繁体   English

如何从Actionscript中定位MXML中的Flex 3数据网格?

[英]How can I target a Flex 3 datagrid in MXML from Actionscript?

I have a datagrid defined in an mxml file (flex 3): 我在mxml文件(flex 3)中定义了一个数据网格:

I am using an external class to connect to a sqlite database and generate some results (this is working and I can trace the results). 我正在使用一个外部类连接到一个sqlite数据库并生成一些结果(这是有效的,我可以跟踪结果)。

How can I target the datagrid generated in the mxml from the external class? 我该如何针对外部类在mxml中生成的datagrid? I have tried: 我努力了:

Application.application.resultsGrid.dataProvider = results.data; Application.application.resultsGrid.dataProvider = results.data;

And get 'Error: Access of undefined property Application.' 并获取“错误:访问未定义属性的应用程序”。 from the amxmlc compiler. 来自amxmlc编译器。

I've also tried: 我也尝试过:

[Bindable]
public var resultsGrid:DataGrid;

In the class properties. 在类的属性。

Looks like I needed to include import mx.core.*; 看来我需要包含import mx.core。*; and it now works. 现在可以了。

I don't really understand your answer. 我不太明白你的回答。 Am I not binding the dataprovider property by doing: 我不是通过执行以下操作来绑定dataprovider属性吗?

Application.application.resultsGrid.dataProvider = result.data; Application.application.resultsGrid.dataProvider = result.data; ?

I'm from a PHP background and familiar with OOP in that environment so the idioms in Flex are quite strange to me. 我来自PHP背景,并且在那种环境下熟悉OOP,所以Flex中的习惯用法对我来说很陌生。

Update: The phrasing of your question confused me :( 更新:您问题的措辞使我困惑:(

If you need to populate the datagrid with from you db, you really should be looking at binding the dataProvider property. 如果需要从数据库中填充datagrid,则实际上应该在绑定dataProvider属性。

as brd664 says, what you are actually doing in 正如brd664所说,您实际在做什么

Application.application.resultsGrid.dataProvider = result.data; 

is actually an assignment. 实际上是一项任务。 It's just like assigning a value to variable as in 就像为变量赋值一样

var a : uint = 1;

Binding gives you a little more structure and allows you to populate multiple components based on a single property update. 绑定为您提供了更多的结构,并允许您基于单个属性更新来填充多个组件。 There's a ton of other benefits from binding and probably too much to cover in this post. 绑定还有很多其他好处,而这篇文章可能涵盖了太多。

Here is a quick and simple example of how binding works. 这是绑定工作原理的简单示例。 Note that there is one property that is bindable... when you click the button it sets that property to the value of whatever is in the textInput. 请注意,有一个可绑定的属性...单击按钮时,它将将该属性设置为textInput中任何值。 This update then causes the bindings to fire and updates anything that has been bound to that property. 然后,此更新将导致绑定触发并更新已绑定到该属性的所有内容。 It's one of flex's biggest features (it's also used extensively in silverlight and wpf and probably a load of other technologies that i'm not aware of). 这是flex的最大功能之一(它在Silverlight和WPF中也得到了广泛使用,可能还有许多我不知道的其他技术)。 Anyway... have a play with it and see if you can get your component to update from a binding. 无论如何...尝试一下,看看是否可以从绑定中更新组件。

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal">

    <mx:Script>
        <![CDATA[

            private var _myData : String

            [Bindable]
            public function get myData() : String
            {
                return _myData;
            }
            public function set myData(value : String) : void
            {
                _myData = value;
            }

            private function clickHandler(event : MouseEvent) : void
            {
                myData = myTextInput.text;
            }
        ]]>
    </mx:Script>
    <mx:VBox>
        <mx:HBox>
            <mx:Label text="{myData}" />
            <mx:Label text="{myData}" />
            <mx:Label text="{myData}" />
        </mx:HBox>
        <mx:TextInput id="myTextInput" text="TYPE HERE" />
        <mx:Button label="CLICK TO BIND" click="clickHandler(event)" />
    </mx:VBox>

</mx:Application>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM