Javascript Ext JS:为存储区中的数据分配一个变量
我想根据用户的url更改项目的某个视图中的值。 目前,我有一个store类,它使用loadStore方法在url中动态加载Javascript Ext JS:为存储区中的数据分配一个变量,javascript,extjs,extjs4,extjs-mvc,Javascript,Extjs,Extjs4,Extjs Mvc,我想根据用户的url更改项目的某个视图中的值。 目前,我有一个store类,它使用loadStore方法在url中动态加载 Ext.define('store.app.appStore', { extend : 'store.Store' , model : 'model.app.appModel' , alias : 'widget.app-appstore' , proxy : { type : 'rest' , url : ''
Ext.define('store.app.appStore', {
extend : 'store.Store'
, model : 'model.app.appModel'
, alias : 'widget.app-appstore'
, proxy : {
type : 'rest'
, url : ''
, reader : {
type : 'json'
}
}
, loadStore : function(id) {
this.getProxy().url = app.getApplication().getAppUrl();
console.log(this.getProxy().url);
this.load({});
}
});
还有一个控制器,它根据id加载url,然后在启动时用数据更新我的表单
Ext.define('controller.app.appController', {
extend : 'Ext.app.Controller',
refs :
{ref : 'appView', selector : 'app-appview'}
],
stores : ['app.appStore'],
init : function() {
this.control({
'app-appview' : {
selectionchange : this.onStartUp
}
});
},
onStartUp : function() {
this.getStore('app.appStore').loadStore();
this.getAppView().updateForm({PARAMETER});
}
但是,我在解决如何为正在加载的数据分配变量时遇到了一个问题,因此在updateForm()方法中,我将用数据替换{(PARAMETER)}
Ext.define('controller.app.appController', {
extend : 'Ext.app.Controller',
refs :
{ref : 'appView', selector : 'app-appview'}
],
stores : ['app.appStore'],
init : function() {
this.control({
'app-appview' : {
selectionchange : this.onStartUp
}
});
},
onStartUp : function() {
this.getStore('app.appStore').loadStore();
this.getAppView().updateForm({PARAMETER});
}
模型如下所示:
Ext.define('model.app.Summary', {
extend : 'Ext.data.Model',
fields : [
'id', 'name', 'address', 'phone', 'optionOne', 'optionTwo'
],
getId : function() {
return this.get('id');
},
getName : function() {
return this.get('name');
},
getAddress : function() {
return this.get('address');
},
getPhone : function() {
return this.get('phone');
},
getOptionOne : function() {
return this.get('optionOne');
},
getOptionTwo : function() {
return this.get('optionTwo');
},
var myObject = Ext.create('Ext.data.ArrayStore', {
model: 'model.app.Summary',
data: [['someid','somename', 'someaddress', 'somephone', 'someoptionOne', 'someoptionTwo']]
});
}))
有什么建议吗?好的,您的代码中必须有如下内容:
Ext.define('model.app.Summary', {
extend : 'Ext.data.Model',
fields : [
'id', 'name', 'address', 'phone', 'optionOne', 'optionTwo'
],
getId : function() {
return this.get('id');
},
getName : function() {
return this.get('name');
},
getAddress : function() {
return this.get('address');
},
getPhone : function() {
return this.get('phone');
},
getOptionOne : function() {
return this.get('optionOne');
},
getOptionTwo : function() {
return this.get('optionTwo');
},
var myObject = Ext.create('Ext.data.ArrayStore', {
model: 'model.app.Summary',
data: [['someid','somename', 'someaddress', 'somephone', 'someoptionOne', 'someoptionTwo']]
});
从要存储的数据创建对象的位置
在本例中,myObject是一个ArrayStore
,这意味着您可以在对象中存储多个项,所有项都具有定义的字段
假设您想要获取myObject
myObject.data.items[0].data.name
我不确定模型中的
getWhatever()
方法。您需要在事件中完成updateForm。例如,将侦听器添加到
然后,在LoadFormData方法中,您可以访问存储区中加载的数据
LoadFormData: function (s) {
var value = s.data.items[0].get('myFieldFromStore');
//insert value where required here
}
你能把这件事解释得更清楚一点吗?我不是100%清楚您希望传递给
updateForm()
method的是什么,所以我正在加载一个包含6个字段(基本模型)的对象。我想将其中一个字段传递到updateForm。您的对象看起来如何?:)