我正在使用fx:Model
s 进行测试,但是将其序列化为 JSON 并没有按预期工作。在下面的示例中,我没有在 JSON 中获取模型的数据,我得到的只是 uuid。如何干净地将模型序列化为 JSON?
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="application1_creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.FlexEvent;
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
mod1.part = "Initial value";
}
]]>
</fx:Script>
<fx:Declarations>
<fx:Model id="mod1">
<data>
<part>{ti.text}</part>
</data>
</fx:Model>
</fx:Declarations>
<s:TextInput id="ti" x="98" y="155" text="{mod1.part}">
</s:TextInput>
<s:Button x="120" y="193" label="Read from model" click="Alert.show(mod1.part, 'Model Data')"/>
<s:Button x="120" y="220" label="Model as JSON" click="Alert.show(JSON.stringify(mod1), 'Model as JSON')"/>