English 中文(简体)
How to embed Json result within Extjs Panel?
原标题:
  • 时间:2009-11-17 07:59:35
  •  标签:
  • json
  • extjs

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.

最佳回答

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!

问题回答

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
});




相关问题
ExtJS load form items/fields from database

I am using ExtJS 3 here. I would like to populate a formpanel from database with fields to be submitted. Basically, I don t know witch fields my form will have and I want to generate all formpanel ...

How to use Ext JS for role based application

I am planning to use Ext JS for a large application. The application s features are role based. When user login, they only see menu and screen features related to them. My server side technology will ...

Dynamically adding a TabPanel to a Panel Region

I have a Panel layout with a TreePanel in one region. A user clicks on an node in the tree and a TabPanel should be displayed in another region with information, editing tools etc. for that tree node....

How to embed Json result within Extjs Panel?

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 ...

Ajax data update. Extjs

I need to keep certain data ( in a grid) up to date and was gonna do a poll to the server every 15 seocnds or so to get the data and refresh the grid, however it feels a bit dirty ( the grid will have ...

Better way to call superclass method in ExtJS

All the ExtJS documentation and examples I have read suggest calling superclass methods like this: MyApp.MyPanel = Ext.extend(Ext.Panel, { initComponent: function() { // do something MyPanel ...

Merged Headers in Ext JS Grid

Is it possible to have two headers in Ext JS grids? I have to show my grid as grouped data.. for example product types and products. In my case I need a grid like this: Field | Product Type A ...

热门标签