如何获取
标记 htmlText 以包裹在 AdvancedDataGridColumn 内

发布于 2024-12-02 12:58:01 字数 1729 浏览 0 评论 0原文

为了在 AdvancedDataColumn 中显示 HTML 格式的文本,我使用了一个自定义渲染器,它是一个 mx:Text 对象。我将 myText.htmlText 设置为“测试文本,它实际上比列宽长很多”。无论我设置什么属性,文本都会从列的末尾延伸出来。

我在 dataGrid 以及每个单独的列上尝试了 wordWrap="true" 。我还尝试弄乱 css 并尝试将其应用到文本字段,但似乎什么也没有显示。有谁能够将 htmlText 包装在文本对象中吗?

另外,但不太重要的是,每个标签后面都有额外的空行,我想删除它们。

--编辑--添加渲染器代码。

<?xml version="1.0"?>
<!-- itemrenderers/sparkmx/myComponents/SummaryRenderer.mxml -->
<s:MXAdvancedDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:mx="library://ns.adobe.com/flex/mx"
    xmlns:s="library://ns.adobe.com/flex/spark"
    textAlign="center">

    <fx:Script>
        <![CDATA[
            import mx.controls.advancedDataGridClasses.AdvancedDataGridListData;

            override public function set data(value:Object):void
            {
                // help for style sheets
                //http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/StyleSheet.html

                //create and initialize css
                var myCSS:StyleSheet = new StyleSheet();
                myCSS.setStyle("p", {textAlign:'left'});
                // TODO try wordwrap here.
                myCSS.setStyle("div", {textAlign:'left'});

                //ensure html support and apply css to it
                myText.styleSheet = myCSS;

                // if the value is null, it would throw an error.
                if (AdvancedDataGridListData(listData) != null) {
                    myText.htmlText = value[AdvancedDataGridListData(listData).dataField];
                }
            }
        ]]>
    </fx:Script>

    <mx:Text id="myText"/>
</s:MXAdvancedDataGridItemRenderer>

To display HTML formatted text in an AdvancedDataColumn, I'm using a custom renderer which is an mx:Text object. I'm setting myText.htmlText to something like "test text which is really a lot longer than the column width". No matter what properties I set though, the text just runs off the end of the column.

I tried wordWrap="true" on the dataGrid and also on each individual column. I also tried messing with css and tried applying it to the text field, but nothing seems to show up. Has anyone been able to wrap htmlText in a text object?

Also, but slightly less important, there are extra blank lines after each tag which I would like to get rid of.

--Edit--added renderer code.

<?xml version="1.0"?>
<!-- itemrenderers/sparkmx/myComponents/SummaryRenderer.mxml -->
<s:MXAdvancedDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:mx="library://ns.adobe.com/flex/mx"
    xmlns:s="library://ns.adobe.com/flex/spark"
    textAlign="center">

    <fx:Script>
        <![CDATA[
            import mx.controls.advancedDataGridClasses.AdvancedDataGridListData;

            override public function set data(value:Object):void
            {
                // help for style sheets
                //http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/StyleSheet.html

                //create and initialize css
                var myCSS:StyleSheet = new StyleSheet();
                myCSS.setStyle("p", {textAlign:'left'});
                // TODO try wordwrap here.
                myCSS.setStyle("div", {textAlign:'left'});

                //ensure html support and apply css to it
                myText.styleSheet = myCSS;

                // if the value is null, it would throw an error.
                if (AdvancedDataGridListData(listData) != null) {
                    myText.htmlText = value[AdvancedDataGridListData(listData).dataField];
                }
            }
        ]]>
    </fx:Script>

    <mx:Text id="myText"/>
</s:MXAdvancedDataGridItemRenderer>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

说谎友 2024-12-09 12:58:01

文本组件中的 HTML 可能性非常有限。您无法在其中添加 div 标签。对于您遇到的问题 - 我想说您需要在自定义渲染器中的文本组件或 AdvancedDatagridColumn 上设置固定宽度。
抱歉,上一个关于空格的问题没能解答您的问题。你能举例说明吗?

The HTML possibilities in Text component are quite limited. You're not able to add div tags in there. For the issue you have - I would say you need to set up fixed width either on your Text component in custom renderer or on AdvancedDatagridColumn.
Sorry, didn't get you in last question about blanks. Could you explain with example?

舂唻埖巳落 2024-12-09 12:58:01

我弄清楚了第一部分。看起来单元格内的 Text 对象比单元格大,因此即使它“包裹”文本,它也认为它有足够的空间。

中添加 a解决了这个问题。

myText.percentWidth=100;
myText.percentHeight=100;

在设置数据函数

I figured out the first part. It looks like the Text object inside the cell was larger than the cell, so even though it was "wrapping" the text, it thought it had plenty of room.

Adding in a

myText.percentWidth=100;
myText.percentHeight=100;

to the set data function solved that problem.

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