在 Spark TextArea 中显示 HTML 文本
下面的代码运行良好...
<?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" >
<fx:Declarations>
<mx:HTTPService id="httpRSS" url="http://www.petefreitag.com/rss/" resultFormat="object" />
</fx:Declarations>
<s:Panel id="reader" title="Blog Reader" width="500">
<mx:DataGrid width="485" id="entries" dataProvider="{httpRSS.lastResult.rss.channel.item}" click="{body.htmlText=httpRSS.lastResult.rss.channel.item[entries.selectedIndex].description}">
<mx:columns>
<mx:DataGridColumn dataField="title" headerText="TITLE"/>
<mx:DataGridColumn dataField="pubDate" headerText="Date"/>
</mx:columns>
</mx:DataGrid>
<mx:TextArea id="body" editable="false" width="485" x="3" y="142" height="155"/>
</s:Panel>
<s:Button label="Load" x="10" y="329" click="{httpRSS.send()}"/>
</s:Application>
但是当 Textarea 更改为 Spark Textrea 时,如下所示
<s:TextArea id="body" editable="false" width="485" x="3" y="142" height="155"/>
htmlText 不支持 Spark Textarea。因此产生错误。如何使用 Spark 文本区域属性显示 HTML 格式的文本。
The Below code is running well...
<?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" >
<fx:Declarations>
<mx:HTTPService id="httpRSS" url="http://www.petefreitag.com/rss/" resultFormat="object" />
</fx:Declarations>
<s:Panel id="reader" title="Blog Reader" width="500">
<mx:DataGrid width="485" id="entries" dataProvider="{httpRSS.lastResult.rss.channel.item}" click="{body.htmlText=httpRSS.lastResult.rss.channel.item[entries.selectedIndex].description}">
<mx:columns>
<mx:DataGridColumn dataField="title" headerText="TITLE"/>
<mx:DataGridColumn dataField="pubDate" headerText="Date"/>
</mx:columns>
</mx:DataGrid>
<mx:TextArea id="body" editable="false" width="485" x="3" y="142" height="155"/>
</s:Panel>
<s:Button label="Load" x="10" y="329" click="{httpRSS.send()}"/>
</s:Application>
But when Textarea is changed to spark Textrea like below
<s:TextArea id="body" editable="false" width="485" x="3" y="142" height="155"/>
Then htmlText doesn't support Spark Textarea. Hence produces error. How does one go about displaying HTML formatted text with spark Text Area Property.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
如果您使用的是 RichEditableText 组件,则可以使用 TextConverter 类来完成此操作
If you're using the RichEditableText component instead, you can do it this way using the TextConverter class
它也可以用在spark textArea中:
如果 HTML 代码很大并且有一些无法呈现的标签,这有时会不起作用
TextFlowUtil.importFromString(yourHTMLString);
It can be also used in spark textArea:
This sometime will not work, if the HTML code is big and have some tags that can`t be rendered
TextFlowUtil.importFromString(yourHTMLString);
body.textFlow = TextFlowUtil.importFromString(yourHTMLString);
body.textFlow = TextFlowUtil.importFromString(yourHTMLString);
我认为你不能。您应该坚持使用 Halo TextArea 组件,或者应该研究文本布局框架来实现您的目标。
I don't think you can. You should stick to using the Halo TextArea component or you should investigate the Text Layout Framework to accomplish your goals.
查看 TextArea 文档。请注意页面末尾的示例..它展示了如何嵌入 HTML。
Check out the content property in the TextArea docs. Note the example at the end of the page.. it shows how to embed HTML.
David Gassner 的 Flashbuilder 4 和 Flashbuilder Flex 4 有一个关于此的部分。
看一下 TextFlowUtil。如果要将 HTML 直接嵌入到 Spark TextArea(或 RichText / RichEditableText)中,可以使用 content 标签作为子标签,然后添加 p 或 span 标签 - 支持的 HTML 标签也是 s 命名空间的一部分。
David Gassner's Flashbuilder 4 & Flex 4 has a section on this.
Take a look at TextFlowUtil. If you want to embed the HTML directly into the Spark TextArea (or RichText / RichEditableText), you can use the content tag as a child, then add the p or span tags thereafter - The supported HTML tags are part of the s namespace too.
还可以使用:
Can also use :