0

在此示例中如何访问 TextInput 值?

我正在使用 Flex 4.5

<s:VGroup id="qItems" width="100%" styleName="qMain">
  <s:HGroup id="id_1"><s:TextInput id="total_1" width="100" text="1.00"/></s:HGroup>
  <s:HGroup id="id_2"><s:TextInput id="total_2" width="100" text="1.00"/></s:HGroup>
  <s:HGroup id="id_3"><s:TextInput id="total_3" width="100" text="1.00"/></s:HGroup>
</s:VGroup>

我只能访问 HGroup id,但我不知道如何深入 TextInput 以添加总文本的值。

这是我用来访问 HGroups 的功能

protected function viewElements(event:MouseEvent):void{
  var messageText:String = "There are " + qItems.numElements + " elements in the MX Panel.";

  for (var i:int = 0; i < qItems.numElements; i++)
  {
    var stringName:String = qItems.getElementAt(i) + "";
    if (stringName.indexOf(".") > 1)
    {
      stringName = stringName.substr(stringName.lastIndexOf(".")+1, stringName.length);
    }
    messageText += "\n" + (i+1) + ". " + stringName;
  }
  Alert.show(messageText, "Show Elements", Alert.OK);
}

谢谢,罗伯特

+++++++++++++++++++++++++++++++++++++++++++++++++

多姆,非常感谢。那效果很好。现在我正在尝试添加这些值,但我使用此函数得到了 NaN 结果

protected function viewElements(event:MouseEvent):void{
  var totalField:Number;
  var sum:Number;
  for (var i:int = 0; i < qItems.numElements; i++)
  {
    var parentGroup:Object = qItems.getElementAt(i);
    for (var j:int = 0; j < parentGroup.numElements; j++) 
    {
      var childGroup:Object = parentGroup.getElementAt(j);
      totalField = childGroup.getElementAt(4).text;
    }
    sum += totalField;
  }
  Alert.show(sum.toFixed(2).toString());
}

你能帮我解决这个问题吗?再次感谢。

4

1 回答 1

1

只需添加另一个 for 循环就可以了

for (var i:int = 0; i < qItems.numElements; i++)
{
    var currentGroup:Object = qItems.getElementAt(i);

    for(var j:int = 0; j < currentGroup.numElements; j++)
    {
        Alert.show(currentGroup.getElementAt(j).text);
    }
}
于 2012-05-02T09:58:40.567 回答