How to use line breaks in Flex with PHP string

烂漫一生 提交于 2020-01-04 09:57:12

问题


This is the MXML I have

<mx:Text id="name" styleName="textStyle" maxWidth="400"></mx:Text>

Then in the same file I have :

<mx:Script>
    <![CDATA[

    private function init():void
    {
       name.text = data.string;
    }

    ]]>
</mx:Script>

data.string comes from the DB and it contains this :

"This is a string \n with two lines."

I also tried this :

"This is a string &#13; with two lines."

None of them create a new line in flex they are both rendered to the screen as \n and &#13;.

How can I create a new line with a string that is coming from the database?

If I type \n like this in the code it works :

name.text = "test \n test"; 

but if I do name.text=data.string; it doesn't even though data.string has the exact same value.


回答1:


I think that you can find something you want in this site.

http://www.switchonthecode.com/tutorials/flex-php-tutorial-transmitting-data-using-json




回答2:


If I run this on the string coming from the DB it works:

string.split("\\n").join("\n");



回答3:


Or you can use String.replace:

string.replace(/\\n/g,'\n')


来源:https://stackoverflow.com/questions/6448510/how-to-use-line-breaks-in-flex-with-php-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!