0

我是 sencha 的新手,我正在尝试填充一些模板,如下所示:

模型:

Ext.define("GS.model.Oferta", {
        extend : 'Ext.data.Model',
        config : {
            fields : [{
                        name : "type",
                        type : "string"
                    }, {
                        name : "logo",
                        type : "string"
                    }, {
                        name : "description",
                        type : "string"
                    }, {
                        name : "product",
                        type : "string"
                    }]
        }
    });

店铺:

Ext.define("GS.store.BoxStore", {
        extend : 'Ext.data.Store',

    config: {
        storeId: 'boxStore',
        model : 'GS.model.Oferta',
        proxy : {
            type : 'ajax',
            url : 'TestData.json',
                reader: {
                    type:'json',
                    rootProperty: 'dataArr'
                }
        },
        autoLoad : true
    }
    });

模板:

Ext.define("GS.view.Box", {
        extend : 'Ext.Panel',
        requires : ['Ext.form.FieldSet'],
        layout : {
            type : 'absolute'
        },

        config : {
            tpl : Ext.XTemplate.from('tp1'),
            data:{}
        }

    });

控制器:

Ext.define('GS.controller.Main', {
 extend: 'Ext.app.Controller',
store: 'boxStore',

config : {
    stores: ['BoxStore'],
    models: ['Oferta'],

    refs : {????
    ????????    },
    control : {
??????????
        }
    }
},

    getData: function(list, index, element, record){
    this.getBox().push({
        xtype: 'panel',
        data :[record.get('type'), record.get('logo'), record.get('logo'),     record.get('product')],
        scrollable: true,
        styleHtmlContent: true
    });
},
//called when the Application is launched, remove if not needed
launch: function(app) {

}
});

HTML:

            <textarea id='tp1' class="tp1">
           <div class="product_small">
             <div class="type" id"type">

             </div>
             <div class="logo"><img src="resources/images/garbarino_logo.png" />
             </div>
             <div class="small_description">
                    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
             </div>
             <div class="product">
                 <span style="color:rgb(0,193,209); font:bold 35px/40px Tahoma,Verdana;">1.700</span><span style="color:rgb(0,193,209); font:bold 13px/20px Tahoma,Verdana;"> puntos</span>
             </div>
            </div>
        </textarea>

我如何设法填充模板?我应该尝试在控制器中创建一个盒子并将其设置在那里吗?

非常感谢伊格纳西奥

4

1 回答 1

1

如果您想直接更新 tpl 的数据,请使用 setData 方法,否则您可能想尝试使用 Ext.DataView 而不是 Ext.Panel 并将数据视图直接链接到商店。很难说出究竟需要什么 - 您的示例代码显示您将一个新面板推送到 getBox(可能是具有模板的组件),但您正试图在没有模板的新面板上设置数据。

于 2012-12-05T05:13:07.387 回答