Flex set value()vs set data()

时间:2012-06-27 09:09:20

标签: flex flex4 flex-spark

我能说的一点是,与整个对象相比,set值只为给定列提供了值。

但是,当您编辑此值时,它只是不保存它。我尝试重写save()方法并返回true,但我仍然没有看到我的值更新。编辑关闭后,值将恢复为编辑前的状态。

什么是它的最佳用例以及如何使用它?

感谢。

<?xml version="1.0" encoding="utf-8"?>
<s:GridItemEditor xmlns:fx="http://ns.adobe.com/mxml/2009" 
                  xmlns:s="library://ns.adobe.com/flex/spark" 
                  xmlns:mx="library://ns.adobe.com/flex/mx">
    <fx:Declarations>
    </fx:Declarations>
    <fx:Script>
        <![CDATA[

            private var _data:Object;

            private var _labelText:String = '';
            private var bTextChanged:Boolean = false;

            override public function set data(newVal:Object):void
            {
                super.data = newVal;
                _data = newVal;
            }

            override public function get data():Object
            {
                return _data;
            }

            override public function set value(newValue:Object):void
            {
                _labelText = newValue as String;
            }

            override public function get value():Object
            {
                return labelTextInput.text;
            }

            override public function setFocus():void
            {
                labelTextInput.setFocus();
            }

            override public function save():Boolean
            {
                if(data.hasOwnProperty("action")) data.action = 'UI_UPDATED';
                return true;
            }

            override protected function commitProperties():void
            {
                super.commitProperties();
                if (bTextChanged)
                {
                    bTextChanged = false;
                    labelTextInput.text = _labelText;
                }
            }
        ]]>
    </fx:Script>
    <s:TextInput id="labelTextInput" prompt="Enter Text" width="100%" height="100%"/>
</s:GridItemEditor>

0 个答案:

没有答案