最近在研究Ext,做了一个ajax调取后台数据再显示出来的demo.
在Panel中要用到store中的数据.
请问如何才能让panel在store.load后才表现出来.谢谢
下面是部分代码
show.jsp
后台传过来的数据
以下是解决方案:
[quote="gdyxml2000"]加上如下代码:
store.on('load', function(_store, _records, _options){
var title = _records[0].get('n_ttitle');
var content = _records[0].get('n_content');
p.setTitle(title);
p.html = content;
p.doLayout();
});[/quote]
在Panel中要用到store中的数据.
请问如何才能让panel在store.load后才表现出来.谢谢
下面是部分代码
show.jsp
Ext.onReady(function(){
if (newsid==''){
Ext.Msg.alert('抱歉','您所输入的文章不存在或已被删除',function(){
history.go(-1);
}
);
};
var store = new Ext.data.JsonStore({
url: 'ajax.jsp?rpc=getnews&id='+newsid,
root: 'root',
fields: ['n_ttitle','n_content',{name:'n_time', type:'date'}],
autoLoad:true
});
var p = new Ext.Panel({
title:'标题',
//title:store.getAt(0).get('n_ttitle'),如果store还未加载就会出错
collapsible:true,
width:800,
html:'文章在这里\u002F'
//html:store.getAt(0).get('n_content'),文章内容
});
p.render('content');
});
后台传过来的数据
{ "root": [{'n_ttitle': '文章标题 ','n_content': '文章内容','n_time': '2008-3-10 14:47:42'}]
}
以下是解决方案:
[quote="gdyxml2000"]加上如下代码:
store.on('load', function(_store, _records, _options){
var title = _records[0].get('n_ttitle');
var content = _records[0].get('n_content');
p.setTitle(title);
p.html = content;
p.doLayout();
});[/quote]