Button 将参数从sencha touch中的视图传递到动作属性
我在视图中有一个按钮,我设置了它的动作属性,这样我就可以在控制器中监听它的点击事件,如下所示Button 将参数从sencha touch中的视图传递到动作属性,button,extjs,properties,sencha-touch-2,Button,Extjs,Properties,Sencha Touch 2,我在视图中有一个按钮,我设置了它的动作属性,这样我就可以在控制器中监听它的点击事件,如下所示 { xtype:'button', text:'SKIP', action:'skip(data.index)' //i want to pass the index of record to the controller } 视图代码 { xtype:'button', text:'SKIP', action:'skip' } 控制
{
xtype:'button',
text:'SKIP',
action:'skip(data.index)' //i want to pass the index of record to the controller
}
视图代码
{
xtype:'button',
text:'SKIP',
action:'skip'
}
控制器代码
onSkipContact:function(){
console.log('tap');
}
现在,我想将参数传递给onSkipContact action如下所示
{
xtype:'button',
text:'SKIP',
action:'skip(data.index)' //i want to pass the index of record to the controller
}
这样我就可以在控制器中读取如下内容
onSkipContact:function(index){
console.log('tap' + index );
}
包含cv
Ext.define('ca.view.ContactInfoPanel',{
extend:'Ext.Panel',
xtype:'contactinfopanel',
requires: [ 'ca.view.ContactInfo','ca.view.ContactVote'],
config:{
layout:'vbox',
defaults: {
margin: '10 10 10 10'
} ,
items:[{
xtype:'contactinfo'
},{
xtype:'contactvote', // its a CV
}]
},
initialize:function(){
this.callParent();
}
});
这是contactvote
即cv
Ext.define("ca.view.ContactVote",{
extend:'Ext.Container',
xtype:'contactvote',
requires:['Ext.Button'],
config:{
bottom:0,
width: '100%',
defaults: {
margin: '10 20 0 0'
} ,
items:[{
xtype:'button',
text:'SKIP',
action:'skip',
id:'skipbtn'
}]
},
initialize:function(){
console.log(this.data);
this.callParent();
}
});
首先,将要传递给处理程序方法的数据存储在按钮本身中。例如:
{
xtype: 'button',
text: 'SKIP',
action: 'skip',
// Give it the name you want, just ensure it won't
// overlap a property defined by Ext.
dataIndex: data.index
}
Ext事件监听器始终作为其第一个参数传递事件源(在您的示例中是按钮)。因此,在处理程序中,您可以通过以下方式访问数据:
onSkipContact: function(button) {
var index = button.index;
console.log('tap' + index);
}
尝试此操作,在按钮配置中设置索引
{
xtype:'button',
text:'SKIP',
action:'skip',
index : data.index
}
控制器动作中
onSkipContact:function(button){
// You can get index config like this
console.log('tap' + button.index );
}
我假设您的控制器中有如下配置
refs: {
skipBtn : 'button[action=skip]'
},
control: {
skipBtn : {
tap: 'onSkipContact'
}
}
更新
试一试
而不是
this.getCV().setData(record.data)
您的按钮代码仍然有效
{
xtype:'button',
text:'SKIP',
action:'skip'
}
哈哈。所以应该发出警报“其他人正在写与你完全相同的东西”^^你也浪费了一些时间来弄清楚这个操作选项是什么,不是吗?@rixo不,我把它作为button的一个属性object@Viswa我得到了
这个.data.index
或数据.index
undefine@Hunt你是说在视野中?您是如何传递数据的。是的,在视图中,我在controllergetCV().setData(record.data)
中按如下方式设置数据。您只需要从controller设置按钮的索引,而不需要其他使用数据的组件。。是吗?是的,我想在我的回答中看到我的更新。你解决了这个问题吗?