ExtJS cannot decode a string with \ n

Source: Internet
Author: User

The last time we stumbled upon a problem, we were in a huge project, followed by spring web flow, last submitted, submitted successfully, but when we returned to a page, there was always an error, saying a variable such as Var projectInfo, which was null.

Then we took a closer look at the code, originally because there is a field on this page is textarea, and then it will support multiline input, multiple lines is \ n, and then in ExtJS's view, it cannot be decode for a string containing \ n, so the result of Decode is null

Our experiment is as follows:

(1) Ext.decode a string containing \ n:

Here you can see that decode will fail.

(2) Ext.decode A string that does not contain \ n or contains all of the \ n transitions to \\n:

See here decode will succeed.

Based on this idea we will find the right solution, we just need all ' \ n ' to replace ' \\n ' on it, for this in the JS code:

The original is:

var projectInfo = Ext.decode (decodeURIComponent (' ${projectinfojsondata} ', true);

Now change to:

var projectInfo = Ext.decode (decodeURIComponent (' ${projectinfojsondata} '). Replace (/\n/g, ' \\n '), true);

This article from the "Cohesion of parallel Lines" blog, please be sure to retain this source http://supercharles888.blog.51cto.com/609344/1222093

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/Extjs/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.