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

来源:互联网 发布:难言之欲网络剧资源 编辑:程序博客网 时间:2024/05/18 02:23

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);                 }       });    }});
原创粉丝点击