sencha touch2 如何在control层给panel应用XTemplate模版,并将store中的数据加载到模版里

model层设置相关字段。

Ext.define("LYT.model.sceneryDetail", {
    extend: 'Ext.data.Model',
    config: {
        fields: ["id","title","content"]
    }
});

store层引用model并设置代理

Ext.define("LYT.store.sceneryDetail", {
    extend: 'Ext.data.Store',
    config: {
        model: "LYT.model.sceneryDetail",
        storeId: "sceneryDetail",
        proxy: {
            type: "ajax",
            url: "article.json",
            reader: {
                type: "json",
                rootProperty: "data"
            }
        }
    }
});

control层对panel进行相关操作

Ext.define("LYT.controller.sceneryList", {
    extend: 'Ext.app.Controller',
    config: {
        refs: {
            getPanel: "#MyPanel"
        }
    },
    launch:function() {
        var getController =  this;
        var getStore = Ext.data.StoreManager.lookup('sceneryDetail');
        getStore.load(function (records, operation, success) {
                 if (success) {
                        var tpl = new Ext.XTemplate([
                               "<h3>{title}</h3>",
                               "<p>{content}</p>"                               
                         ]);
                          var html = tpl.applyTemplate(getStore.getAt(0).getData());
                          getController.getGetPanel().setHtml(html);
                 }
       });
    }
});

 

posted on 2012-10-19 23:41  一青鸟一  阅读(1928)  评论(0编辑  收藏  举报

导航