tags:

views:

2355

answers:

2

Hi,

I have some issues with Json result and embed it within the html of the Extjs Panel.

Here's that I have managed to get so far. myPanel is embedded within a mainPanel, and I have some shows/hide of the myPanel in between other sections of my codes.

Ajax request to retrieve Json result like so:

Ext.Ajax.request({
    url: 'myStore',
    success: function(r) {
        var myItem = Ext.decode(r.responseText).itemName;
    }
})

I would like to embed the myItem into mypanel, something like this:

var myPanel = new Ext.Panel({
    hidden: true,
    html:myItem
})

This is where the myPanel is embedded to my mainPanel:

var mainPanel = new Ext.Panel({
    applyTo: 'mywizard',
    frame: true,
    items: [{
        id: 'top',
        xtype:'panel',
        items: [
            topPanel1,
            topPanel2
        ]
    },{
        id: 'middle',
        xtype: 'panel',
        items: [
            middlePanel1,
            middlePanel2,
            myPanel
        ]
    },{
        id: 'bottom',
        xtype: 'panel',
        items: [
            footer        
        ]
    });

Currently if I were to run the code, I got a "undefined" within the myPanel, so I supposed that myItem is out of the scope, hence not picked up by myPanel. Hence, I would like to know how/what should I do to be able to get myItem (Json result) reflected in the myPanel?

Thank you.

A: 

you have a syntax error in this part the corrected code look like this :

var myPanel = new Ext.Panel({
    hidden: true,
    html:myItem // no ; here
});

also you have to be careful about scoping issue, if your code is in a class I would do something like that

Ext.Ajax.request({
    url: 'myStore',
    success: function(r) {
        var myItem = Ext.decode(r.responseText).itemName;
        var myPanel = new Ext.Panel({
             hidden: true,
             html:myItem // no ; here
        });
        this.parentPanel.add(myPanel);
    }
    ,scope: this // note the set the scope
});
RageZ
Thanks, corrected the error.
jl
@jl: would you be approve the answer ?
RageZ
@jl: thanks a lot!
RageZ
@RageZ: Sorry I can't accept the answer, because aside from the syntax error, I am still unable to get the myItem to show up in my panel. It's still a variable out of scope issue.
jl
@jl: can you update your question and show me the whole code please ?
RageZ
@RageZ: I have almost 2000 plus lines of code, it's supposed to be a wizard. I only have problem with this, basically the question is how to grab the json result and concat to the html portion of a panel.
jl
@RageZ: I mean how you retrieve the HTML content and the panel creation. on your question `var myItem` is used in the success method and in the panel but those two are in the same scope ?
RageZ
@RageZ: After I followed your sample, I have a new problem `comp is undefined`.
jl
I think there is something wrong in your panel, you should install firebug on firefox and take a look at the stack trace when the error occurs
RageZ
@RageZ: Thanks for your help! I have managed to solve my problem. Have posted the solution already. Thank you. :)
jl
A: 

I found the answer, tested and working for me. For any friends stuck with this. What I need to do is just to update the html content with the body update.

Basically, just grab the middle out of mainPanel such that:

var middle = new Ext.Panel({
    id: 'middle',
    xtype: 'panel',
    items: [
        middlePanel1,
        middlePanel2,
        myPanel
    ]
})

Of course, you will need to replace the middle back into the mainPanel.

Then, next is to create the myPanel as norm:

var myPanel = new Ext.Panel({
    id: 'myPanel',
    hidden: true,
    html: 'empty'
})

Inside the Ajax request, you update

Ext.Ajax.request({
    url: 'myStore',
    success: function(r) {
        var myItem = Ext.decode(r.responseText).itemName;
        var editmycontent = Ext.getCmp('myPanel');
            editmycontent.body.update(myItem);  // update myItem here
        middle.doLayout();  // refresh the changes
    }
})

That's it!

jl
There is no need for "html: 'empty'"
bmoeskau