Sencha touch -如何在面板的initcomponent函数中使用数据存储
sencha touch - how to use data store in initcomponent function of panel
如何在面板的initcomponent中读取json对象(ajax调用的结果)。我使用了以下代码
initComponent : function() {
Ext.regModel('allVisit', {
fields: [
{ name: 'visitDate', type: 'date'},
{ name: 'doctorInfo', type: 'string'},
{ name: 'patientId', type: 'string'},
{ name: 'visitType', type: 'string'},
{ name: 'referedBy', type: 'string'},
{ name: 'visitId', type: 'string'},
]
});
var allVisitStore = new Ext.data.Store({
model: 'allVisit',
autoLoad : true,
proxy: {
type: 'ajax',
id: 'allvisit_app_localstore',
url: '/RadMobApp/api',
extraParams:{
action:'test',
queryName:'GET_ALL_test',
retFormat:'XML',
patId: '123',
keyValuePair:'yes'
},
// the return will be XML, so lets set up a reader
reader: new Ext.data.XmlReader({
// records will have an "T4" tag
record: 'data'
})
}
});
var jsonObj = [];
allVisitStore.load();
allVisitStore.data.each(function() {
jsonObj.push({xtype:"panel", title: this.data['visitDate'] + " (" + this.data['visitType'] + ") " + this.data['doctorInfo'] , html : this.data['patientId'], style : 'padding-bottom:10px;'});
});
this.items = jsonObj;
RadMobApp.views.clinicalPanel.superclass.initComponent.call(this);
}
在接收ajax请求值之前执行数据存储迭代代码(如下所示)。我对以下代码集使用了setTimeOut函数
var jsonObj = [];
allVisitStore.load();
allVisitStore.data.each(function() {
jsonObj.push({xtype:"panel", title: this.data['visitDate'] + " (" + this.data['visitType'] + ") " + this.data['doctorInfo'] , html : this.data['patientId'], style : 'padding-bottom:10px;'});
});
this.items = jsonObj;
RadMobApp.views.clinicalPanel.superclass.initComponent.call(this);
但是没有用,我明白了。
像这样使用load函数,这将确保它在存储被加载后执行!
activityStore.load(function(records, operation, success) {
console.log('num of activities loaded: ' + activityStore.data.length);
});
相关文章:
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 将函数的上下文应用于javascript变量
- 如何在JavaScript中将字符串转换为函数引用
- 用嵌套函数和默认函数定义函数
- 使用 jQuery 的 .on 函数如何获取事件的原始元素
- 无法导出函数expressjs/requestjs中的变量
- 函数参数中的数据与指定变量之间的任何性能差异
- JQuery合并了keyup和focusout两个函数
- ES6构造函数返回基类的实例
- 监视函数从服务返回不起作用,但作用域函数起作用
- 我可以在json对象中添加一个函数吗
- AngularJS:我可以跳过函数参数回调吗
- 如何使jQuery插件函数可调用以供独立使用,而不在集合上操作
- JavaScript数组排序(函数)用于对表行进行排序,而不是排序
- jquery点击函数select&取消选择
- 拨打'父亲'函数形式a'儿童'ReactJS中的组件
- Node.js v6.2.0类扩展不是函数错误
- 在 initComponent Ext JS4 中声明函数
- Sencha touch -如何在面板的initcomponent函数中使用数据存储
- 如何在Extjs中用initComponent替换构造函数