在 Spark TextArea 中显示 HTML 文本

发布于 2024-09-11 02:56:19 字数 1307 浏览 2 评论 0原文

下面的代码运行良好...

<?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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

下壹個目標 2024-09-18 02:56:19

如果您使用的是 RichEditableText 组件,则可以使用 TextConverter 类来完成此操作

var myStr:String = "I contain <b>html</b> tags!";           
myRichEditableText.textFlow = TextConverter.importToFlow(myStr, TextConverter.TEXT_FIELD_HTML_FORMAT);

If you're using the RichEditableText component instead, you can do it this way using the TextConverter class

var myStr:String = "I contain <b>html</b> tags!";           
myRichEditableText.textFlow = TextConverter.importToFlow(myStr, TextConverter.TEXT_FIELD_HTML_FORMAT);
帅冕 2024-09-18 02:56:19

它也可以用在spark textArea中:

var myStr:String = "我包含 html 标签!";
textAarea.textFlow = TextConverter.importToFlow(myStr, TextConverter.TEXT_FIELD_HTML_FORMAT);

如果 HTML 代码很大并且有一些无法呈现的标签,这有时会不起作用
TextFlowUtil.importFromString(yourHTMLString);

It can be also used in spark textArea:

var myStr:String = "I contain html tags!";
textAarea.textFlow = TextConverter.importToFlow(myStr, TextConverter.TEXT_FIELD_HTML_FORMAT);

This sometime will not work, if the HTML code is big and have some tags that can`t be rendered
TextFlowUtil.importFromString(yourHTMLString);

平定天下 2024-09-18 02:56:19

body.textFlow = TextFlowUtil.importFromString(yourHTMLString);

body.textFlow = TextFlowUtil.importFromString(yourHTMLString);

紙鸢 2024-09-18 02:56:19

我认为你不能。您应该坚持使用 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.

执手闯天涯 2024-09-18 02:56:19

查看 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.

夏日落 2024-09-18 02:56:19

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.

何处潇湘 2024-09-18 02:56:19

还可以使用:

(myTextArea.textDisplay as StyleableTextField).htmlText = text;

Can also use :

(myTextArea.textDisplay as StyleableTextField).htmlText = text;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文