Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript SAPUI5:如何获取一行的索引?_Javascript_Indexing_Row_Sapui5 - Fatal编程技术网

Javascript SAPUI5:如何获取一行的索引?

Javascript SAPUI5:如何获取一行的索引?,javascript,indexing,row,sapui5,Javascript,Indexing,Row,Sapui5,我有一个问题,事实上我无法检索表中该行的索引。我尝试了很多方法,但都没有找到解决办法。这是我的密码: <script id='TableSuser'> var oTableSuser = new sap.ui.table.Table({editable:false, width: "400px", visibleRowCount:2}); var oControl = new sap.ui.commons.Button({text : "{suser}", press : func

我有一个问题,事实上我无法检索表中该行的索引。我尝试了很多方法,但都没有找到解决办法。这是我的密码:

<script id='TableSuser'>
var oTableSuser = new sap.ui.table.Table({editable:false, width: "400px", visibleRowCount:2});
var oControl = new sap.ui.commons.Button({text : "{suser}",  press : function() {openDialog(oTableSuser.getSelectedIndex());}});
oTableSuser.addColumn(new sap.ui.table.Column({label: new sap.ui.commons.Label({text: "Suser"}), template: oControl, sortProperty: "Button", filterProperty: "Button", name: "password_colonne"}));
oControl = new sap.ui.commons.TextView({text:"{suser_mdp}"});
oTableSuser.addColumn(new sap.ui.table.Column({label: new sap.ui.commons.Label({text: "suser_mdp"}), template: oControl, sortProperty: "suser_mdp", filterProperty: "suser_mdp", visible: false}));

var oModel = new sap.ui.model.json.JSONModel();
oModel.loadData("suser.php");
oTableSuser.setModel(oModel);
oTableSuser.bindRows("/");

function openDialog(index) {
var currentRowContext = oTableSuser.getContextByIndex(index);
var valeur_suser_mdp = oModel.getProperty("suser_mdp",currentRowContext); 

alert(index);
alert(currentRowContext);
alert(valeur_suser_mdp);
oTableSuser.getColumns()[1].setVisible(true);
};
oTableSuser.placeAt("suser");
</script>

var oTableSuser=new sap.ui.table.table({可编辑:false,宽度:“400px”,visibleRowCount:2});
var oControl=new sap.ui.commons.Button({text:{suser}),按:function(){openDialog(oTableSuser.getSelectedIndex());});
oTableSuser.addColumn(新的sap.ui.table.Column({label:new sap.ui.commons.label({text:“Suser”}),模板:oControl,sortProperty:“Button”,filterProperty:“Button”,name:“password_colonne”});
oControl=new sap.ui.commons.TextView({text:{suser\u mdp}}});
oTableSuser.addColumn(新的sap.ui.table.Column({label:new sap.ui.commons.label({text:“suser_mdp”}),模板:oControl,sortProperty:“suser_mdp”,filterProperty:“suser_mdp”,visible:false});
var oModel=new sap.ui.model.json.JSONModel();
loadData(“suser.php”);
oTableSuser.setModel(oModel);
oTableSuser.bindRows(“/”);
函数openDialog(索引){
var currentRowContext=oTableSuser.getContextByIndex(索引);
var valeur_suser_mdp=oModel.getProperty(“suser_mdp”,currentRowContext);
警报(索引);
警报(currentRowContext);
警报(valeur_suser_mdp);
oTableSuser.getColumns()[1].setVisible(true);
};
oTableSuser.placeAt(“suser”);
调用函数function(){openDialog(oTableSuser.getSelectedIndex());}

我尝试了不同的方法,但没有找到如何检索该行的索引,我总是使用“-1”
如果有人有我感兴趣的想法?:)

您正在向模板函数传递一个变量,该函数不起作用(在渲染时,未选择任何内容,因此-1)

最好让您的代码如下所示:

var oControl = new sap.ui.commons.Button({
    text  : "{suser}",  
    press : oController.openDialog
});
在控制器中,定义
openDialog
方法如下:

openDialog: function(oEvent) {
    var tbl   = sap.ui.getCore().byId("id_of_your_table"),
        index = tbl.getSelectedIndex();
}

可能有点晚了,但这可能有助于寻找解决方案

如果您有表的id或表对象,则只需执行以下操作即可获得所选索引

`var table = sap.ui.getCore().byId("you table id");
var index=parseInt(表._aSelectedPaths[0]。替换('/',''),10)`

或 如果您想在row press事件上获取索引,那么您只需在回调函数中执行以下操作

onRowPress:功能(evt)
{
var index=parseInt(evt.getSource()。_aSelectedPaths[0]。替换('/',''),10);

}

那么你可能打错了。。。控制台中有错误吗?