最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ExtJs textarea with formatting - Stack Overflow

programmeradmin2浏览0评论

I'm trying to add formatted json string to my textarea field. But it doesn't work.

I'm formatting string using this approach: How can I beautify JSON programmatically?

and then just call

textarea.setValue(formattedJson);

Check the snapshot of result:

Is it poosible to get correctly formatted string in the textarea?

I'm trying to add formatted json string to my textarea field. But it doesn't work.

I'm formatting string using this approach: How can I beautify JSON programmatically?

and then just call

textarea.setValue(formattedJson);

Check the snapshot of result:

Is it poosible to get correctly formatted string in the textarea?

Share Improve this question edited May 23, 2017 at 12:13 CommunityBot 11 silver badge asked Feb 8, 2012 at 8:36 Andrey SelitskyAndrey Selitsky 2,6043 gold badges29 silver badges42 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

The JSON.stringify method takes Object as parameter. You probably send string as parameter. This is correct code:

jsonObj = {a: 'b', c: [1,2,3]};
// note that jsonObj is object, not string
jsonString = JSON.stringify(jsonObj, null, '\t');

textarea.setValue(jsonString);

Here is jsfiddle

发布评论

评论列表(0)

  1. 暂无评论