PDA

View Full Version : Help on Ext.decode



pathum
13 Sep 2010, 10:11 PM
Hi,

I m designing a window from Ext JS where I need to get some value from the DB through JSON Object and then display it on a FormPanel, top of the Window.
I got the JSON Object, but I cannot get hold into the inner elements. I ve used Ext.decode function as follows.

var textArch = Ext.util.JSON.decode(responseObj.responseText).archive;once I set the the textArch to my FormPanel (id: disp_Field), it shows [object Object].
For that I used the following code.

Ext.getCmp('disp_Field').setValue(textArch);My responseObj.responseText looks like this.

{"archive":{"textArchive":"<?xml version=\"1.0\" ?>\}}What I need to print is the inner XML.

Animal
13 Sep 2010, 10:16 PM
Well assuming you have a typo in you post, and your responseText is in fact valid (There's a missing quote if you READ it), textArchive is an Object.

textArch should be



{
textArchive: "<?xml version=\"1.0\" ?>"
}

pathum
13 Sep 2010, 10:23 PM
yes yes. I corrected it, but the result is the same. It shows object Object. Is there anyway of accessing the inner XML? So that I could directly set it to my DisplayField?

Animal
13 Sep 2010, 10:30 PM
"inner XML"?

You have an object with a string property! Don't you know Javascript?

pathum
13 Sep 2010, 10:34 PM
Yes. I m really a novice to JS and for Ext. But why it prints as object. I tried the toString() method. But still the same.
But when I


console.log(textArch);

it shows me the structure as Object{txtArchive="<XML>"}

Animal
13 Sep 2010, 10:37 PM
Yes. What is the problem here? You have an object with a string property, and you want to access that string?

Is this not just Javascript?

pathum
13 Sep 2010, 10:45 PM
I really appreciate what you are doing here.
I tried

Ext.getCmp('disp_Field').setValue(textArch.textArchive);
but it is giving me some garbage values.

pathum
13 Sep 2010, 10:57 PM
I think this might be some of the issues of DisplayField. I tried with a Label and it worked like a charm.

Animal
13 Sep 2010, 11:47 PM
I really appreciate what you are doing here.
I tried

Ext.getCmp('disp_Field').setValue(textArch.textArchive);
but it is giving me some garbage values.


What do you mean "garbage values"?

Have you tried debugging?

Setting the value of a text field to a string works fine.

Animal
13 Sep 2010, 11:49 PM
Ah.

DisplayField.

That's just a <div> so you will have to encode that because it has "<" tags in it.

http://dev.sencha.com/deploy/ext-3.3-beta1-6976/docs/?class=Ext.util.Format&member=htmlEncode

Condor
13 Sep 2010, 11:53 PM
This DisplayField override (http://www.sencha.com/forum/showthread.php?62951-OPEN-640-DisplayField-to-be-able-to-format-data.) might come in handy when tyring to htmlEncode the value.

pathum
14 Sep 2010, 1:14 AM
Ah.

DisplayField.

That's just a <div> so you will have to encode that because it has "<" tags in it.

http://dev.sencha.com/deploy/ext-3.3-beta1-6976/docs/?class=Ext.util.Format&member=htmlEncode

yeah. Thats it!! Many thanks.

BTW, The XML formatting, specially the indentation is gone, when the text is added to either DisplayField or Label. Is there any thing I can do to preserve them as it is? Only the line breaks are available.

Condor
14 Sep 2010, 1:29 AM
Include the XML in a <pre> element or apply css {white-space: pre}

Animal
14 Sep 2010, 1:31 AM
Or instead of using a DisplayField, use a read-only TextArea

That way, you do not need to encode, and it displays whitespace.

pathum
14 Sep 2010, 1:50 AM
Or instead of using a DisplayField, use a read-only TextArea

That way, you do not need to encode, and it displays whitespace.

Perfect! Thanks a lot. You saved my day!