简体   繁体   中英

Create Ext.panel dynamically

In my app I receive some objects in Json. I want to create one panel that shows a single object. If I receive 2 objects, create 2 panels with his content and if I receive 100: 100 panels.

I tried to use a for with .add and .doLayout but never shows any panel. In my console shows the creation of panels, but never renders into my principal panel container . What im doing wrong?

thats my code:

success : function(response) {
    var jsonResp = Ext.util.JSON
            .decode(response.responseText);
    //              Ext.Msg.alert("Info", "UserName from Server : " + jsonResp.message);

    // Limpiamos el array para tener solo las propiedades que se usarán
    jsonResp.forEach(function(currentItem) {
        delete currentItem["cls"];
        delete currentItem["estandar"];
        delete currentItem["iconCls"];
        delete currentItem["leaf"];
        delete currentItem["objetivo"];
        delete currentItem["observaciones"];
        delete currentItem["porcentaje"];
        delete currentItem["salvaguardas"];
        delete currentItem["tieneDocs"];
        delete currentItem["tipoNombre"];
        delete currentItem["responsable"];
        delete currentItem["responsableId"];
        delete currentItem["idReal"];
        delete currentItem["tipoNombre"];
        delete currentItem["tipo"];
        delete currentItem["calculado"];
        delete currentItem["text"];
    });
    var children = [];
    console.log(jsonResp);
    var sumarvariable = 0;
    //add children to panel at once
    for ( var i in jsonResp) {
        if (i < jsonResp)
            var panel = new Ext.Panel({
                id : 'pregunta' + sumarvariable,
                html : sumarvariable

            })
        console.log(panel)
        Ext.getCmp("contenedor").add(panel);
        Ext.getCmp("contenedor").doLayout();
        sumarvariable++;
    }
},

Change that for and use a .forEach like you're using in your jsonResp.forEach under your second comment. This code creates one panel and add it to your "contenedor".

            //Create Panel with every object
            var i = 0;
            jsonResp.forEach(function(currentItem) {
                i++;
                var panel = new Ext.Panel({
                    id: 'jsonObject' + i,
                    html: 'Object' + i
                })
                //Add to your object "contenedor"
                Ext.getCmp("contenedor").add(panel);
            });
            //Force reload and shows every panel
            Ext.getCmp("contenedor").doLayout();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM