5

在 flex builder 4.6 中,我试图绑定来自 am sql 查询的数据,显示在<s:List>带有项目渲染器的<s:Textarea>

我的代码如下:

<s:List id="listapagar" x="304" y="276" width="330" height="42" borderVisible="false"
        color="#FF0000" dataProvider="{dataProvider}" enabled="false" fontSize="22"
        fontStyle="italic" fontWeight="bold" labelField="nome" textAlign="center"
        textDecoration="underline">
    <s:itemRenderer>
        <fx:Component>
            <s:ItemRenderer>
            <s:TextArea id="apagar" width="330" height="42" text="R$ {data.valorapagar}" />      
            </s:ItemRenderer>
        </fx:Component>
    </s:itemRenderer>
</s:List>

在这里,我的 sql 通过以下方式显示<s:list>

protected function buttonX():void
        {
            var sqlConnection:SQLConnection = new SQLConnection();
            sqlConnection.open(File.applicationDirectory.resolvePath("testeDb.sqlite"));

            var stmt:SQLStatement = new SQLStatement();
            stmt.sqlConnection = sqlConnection;
            stmt.text = "SELECT * FROM comandatual order by numerodatransacao desc limit 1 ";
            stmt.execute();

            dataProvider = new ArrayCollection(stmt.getResult().data);
        }

之后,我尝试获取 s:TextArea id="apagar" 显示的结果并与另一个文本区域绑定,以执行简单的减法计算,如下所示:


<fx:Binding source="apagar.text" destination="restroco.text"/>

<fx:Model id="Calculos" >

        <Calculos>
            <!-- Perform a calculation. -->
            <a>{(Number(restroco.text)) - 3}</a>
            </Calculos>
    </fx:Model>

但是此时,flex返回一个不能让我前进的错误:

1120:访问未定义的属性 apagar。弹性问题


所以,我被卡住了,如果有人想查看我的完整代码,他们在这里:

http://freetexthost.com/srxslotf1x

4

1 回答 1

0

正如@RIAStar 解释的那样,您fx:Model无法访问apagar. 除了建议的解决方案,您还可以使用IndexChangeEvent

<fx:Script>
    <![CDATA[
        import spark.events.IndexChangeEvent;

        private var apagarNum:Number = NaN;

        protected function selectionChangedHandler(event:IndexChangeEvent):void
        {
            apagarNum = Number(listapagar.selectedItem.valorapagar);
        }

    ]]>
</fx:Script>

<fx:Model id="Calculos" >
    <Calculos>
        <!-- Perform a calculation. -->
        <c>{(Number(restroco.text)) - 3}</c>
        <!-- calcular com valor a pagar -->
        <d>{apagarNum - 3}</d>
    </Calculos>
</fx:Model>

<s:List id="listapagar" change="selectionChangedHandler(event)" ...>
于 2014-07-15T18:27:24.840 回答