【发布时间】:2016-10-01 18:07:50
【问题描述】:
可以在表单中自动运行 ViewController 中的方法吗?我需要创建应基于来自该控制器的数据的复选框组。在 ViewController 的这个方法中,我从 JSON 文件中获取数据,在这里我正在更新一个视图。当我在视图中的侦听器中有一个按钮时一切正常,但它应该自动运行,并且复选框应该基于此存储数据构建
onClickLoadData: function(){
console.log('onClickLoadData runned');
var gridStore = this.getStore('perosnellstore');
var columnsArray = this.getStore('perosnellstore').getProxy().getReader().rawData.cols.columns;
console.log(columnsArray.length);
for( var i = 0; i < columnsArray.length; i++){
var checkbox = Ext.create('Ext.form.field.Checkbox', {
boxLabel: columnsArray[i].text,
x: 0,
y: i * 30
});
Ext.ComponentQuery.query("#checkBoxGroupModules")[0].add(checkbox);
}
}
和 ViewModel 类:
Ext.define('Message.web.view.edit.EditViewModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.edit',
data:{
title: ''
},
stores : {
perosnellstore: {
fields : ['name'],
autoLoad: true,
proxy: {
type: 'ajax',
url : 'resources/response.json',
reader: {
type: 'json',
rootProperty: 'cols.columns',
keepRawData: true
}
}
}
}
});
【问题讨论】:
-
自动运行是什么意思?它应该在什么时候运行?多少次?
-
一次,加载视图后。我在配置商店时遇到问题,所以我这样做了,但我不确定这是否正确。我尝试使用 initComponent 方法,但该方法是在应用程序启动后调用的。
标签: javascript extjs extjs6