项目中遇到一个参数传递的问题,一直没有办法解决,最近终于解决了,现分享给大家
view层:
Ext.define('app.view.Empma', {
extend: 'Ext.panel.Panel',
alias: 'widget.xEmpma',
title: '测试',
iconCls: 'icon-empma',
forceFit: true,
id:'empma',
tbar: [{
iconCls: 'icon-folderinput',
text: '获取信息',
action: 'getMssages'
}],
items:[//item动态插入
],
store: 'Empma'
});
controller层:
Ext.define('app.controller.Empma', {
extend: 'Ext.app.Controller',
refs: [{
ref: 'Empma',
selector: 'xEmpma'
}],
models: ['Empma'],
stores: ['Empma'],
init: function() {
this.control({
'xEmpma button': {
accept: this.onEmpAccept
}, //传递参数类型
'xEmpma button[action=rejected]': {
click: this.onEmpRejected
}, //不传递参数类型
'xEmpma button[action=getMssages]': {
click: this.onEmpGetMssages
}
});
},
onEmpGetMssages:function(){
fc = Ext.getCmp('empma');
fc.removeAll(); //移除fc中的内容,为添加item做准备
Ext.Ajax.request({
url:'./data/empma.txt',
success:function(response,options){
var tStrr = response.responseText;
var tStrrjson=eval("("+tStrr+")");
var tStrrjsonErcode = tStrrjson["AuthId"];
var DestPlatforms = tStrrjson["DestPlatform"];
var SrcPlatform = tStrrjson["SrcPlatform"];
for(var i=0;i < DestPlatforms.length;i++){
var items = {
xtype :'form',
frame : false,
border : 0,
method : 'POST',
layout : 'column',
items : [{
id :'address_to'+i,
name :'address_to'+i,
xtype: 'component',
margin : 15,
columnWidth:.3,
html: '源ID:'+SrcPlatform.Id
},{
id :'address_from'+i,
name :'address_from'+i,
xtype: 'component',
margin : 15,
columnWidth:.3,
html: '目的ID:'+DestPlatforms[0].Id
},{
id :'address_interval'+i,
name :'address_interval'+i,
xtype: 'component',
margin : 15,
columnWidth:.24,
html: '时长:'+DestPlatforms[0].TermValidity
},{
id :'address_accept'+i,
xtype: 'button',
name:'address_accept'+i,
text: ' 同 意 ',
margin : 15,
columnWidth:.08,
//action:'accept',
handler: function (test) {
this.fireEvent('accept', test);
}
},{
id :'address_rejected'+i,
xtype: 'button',
name :"address_rejected"+i,
text: ' 拒 绝 ',
columnWidth:.08,
margin : 15,
action:'rejected'
}]
//生成item
};
fc.add(items);
fc.doLayout();
};
},
failure:function(){
alert("failure");
}
});
},
onEmpAccept: function(test) {
alert(test.id);
}
});
案例中用到的json:
{
"AuthId": "666",
"SrcPlatform": {
"Id": "s",
"name": "b"
},
"totalCount":3,
"DestPlatform": [
{
"Id": "1",
"Name": "d1",
"TermValidity": "25"
},
{
"Id": "2",
"Name": "d2",
"TermValidity": "36"
},
{
"Id": "3",
"Name": "d3",
"TermValidity": "123"
}
]
}
以上就是在Extjs中使用MVC模式传递参数和不传递参数的写法。
如有疑惑,欢迎留言。
如有疑惑,欢迎留言。
感谢阅读,感谢订阅。