[b]我想要在XTtemplate中添加一个链接的单击事件,当点击链接在同一页面的另一个Panel中显示数据并重新加载,请问怎么做呀?[/b]
[color=blue]XTtemplate中自带的事件不行,因为它在进入页面时就加载了,我要点击之后才加载。[/color]
下面的我的[b]ExtJS代码[/b]:
createFlowConsole : function() {
var data = ['actionId','name'];
this.store = new Ext.data.JsonStore({
url: _ctx.base + '/osworkeflow/getAvailableActions.action',
root:'action',
fields: data
});
var xtpl = new Ext.XTemplate(
'<tpl for=".">',
'<tpl if="xindex % 2 == 1">',
'<div class="x-grid3-cell-inner" style="font-size:10px; background-color:#FFFFFF; border-bottom:1px solid #EDEDED"">',
'<span class="" style=" padding-left:30px;"><a id="showMySteps" href="javaScript: onclick={[this.test()]}">{name}</a></span></div>',
'</tpl>',
'<tpl if="xindex % 2 == 0">',
'<div class="x-grid3-cell-inner" style="font-size:10px; background-color:#FAFAFA; border-bottom:1px solid #EDEDED"">',
'<span class="" style=" padding-left:30px;"><a href="#">{name}</a></span></div>',
'</tpl>',
'</tpl>',{
test : function(){
alert("ok");
}
}
);
this.availableActionsPanel = new Ext.Panel( {
id : 'mySteps_panel',
region : 'north',
title : '我的步骤',
margins : '0 0 5 0',
height : 150,
items: new Ext.DataView({
store: this.store,
tpl: xtpl,
autoHeight:true,
multiSelect: true,
overClass:'x-view-over',
itemSelector:'div.thumb-wrap',
emptyText: 'No data to display'
})
});
this.steps = this.createSetpsGrid();
var flowConsole = new Ext.Panel( {
region : 'center',
layout : "border",
border : false,
items : [ this.availableActionsPanel, this.steps ],
margins : '5 5 5 0'
});
return flowConsole;
}
详细如下附件图所示 :
我吧测试代码给你瞧吧。应该是你哪里写错了,不然不会出现你说的情况
[code="java"]
function test() {
alert('onclick');
}
Ext.onReady(function() {
this.store = new Ext.data.JsonStore({
data : [{
name : 'aaa'
}],
fields : ['name']
});
// window.test = function() {
// alert('onclick');
// }
var xtpl = new Ext.XTemplate(
'',
'',
'
this.availableActionsPanel = new Ext.Panel({
id : 'mySteps_panel',
region : 'north',
title : '我的步骤',
margins : '0 0 5 0',
height : 150,
items : new Ext.DataView({
store : this.store,
tpl : xtpl,
autoHeight : true,
multiSelect : true,
overClass : 'x-view-over',
itemSelector : 'div.thumb-wrap',
emptyText : 'No data to display'
})
});
var win = new Ext.Window({
width : 500,
height : 200,
layout : 'fit',
items : this.availableActionsPanel
})
win.show();
})[/code]
XTemplate 在解析的时候会对 {[this.test()]} 处理。
换成这种写法
[code="java"]{name} [/code]
window.test = function() {//添加一个test事件函数
alert('onclick');
}