【发布时间】:2011-09-29 13:56:05
【问题描述】:
在我的应用程序中,第一页在底部显示了一个 tabPanel。但是选项卡的数量、它们的标签和图标是来自 json 请求的动态内容。我想知道该怎么做。这是我尝试过的。
TMDemo = new Ext.Application({
name: 'TMDemo',
launch: function(){
this.views.mainTabBar = new this.views.MainTabBar();
}
});
TMDemo.views.MainTabBar = Ext.extend(Ext.TabPanel,{
fullscreen: true,
tabBar:{
dock:'bottom',
layout:{
pack:'center'
}
},
addItems: function(){
this.add(addItemsBasedOnJsonData());
this.doLayout(); // important
},
listeners: {
beforerender:function(){
Ext.util.JSONP.request({
url: 'app/data/tabbar.json',
callbackKey: 'callback',
callback: function(result) {
console.log("Inside callback");
TMDemo.tabBarData = result;
}
});
}
render: function(){
console.log("Inside render");
this.addItems();
}
}
});
这里的 tabbar 数据来自 tabbar.json(虚拟数据实际是一些 URL)。我通过 addItemsBasedOnJsonData() 函数将项目添加到此选项卡面板,该函数将创建选项卡项并返回数组。 但问题是渲染事件总是先触发,然后是 JSON 请求回调,因此没有 jsondata 可用于动态创建选项卡。 请引导我走向正确的方向。这种方法是否正确。我可以找任何例子吗?
塔伦
【问题讨论】:
标签: tabs sencha-touch extjs