This should just do it (no need for setting the innerHTML) :
press : function() {
oTable.setVisible(false);
}
質問
I am trying to hide a table on my HTML page. So I use oTable.setVisible(false). This works fine, i.e my table is hidden but I get the text in place of table as shown below in the picture. Is there any way to not display that or any reason why is it been displayed? I paste below my code and also the picture for reference.
View.js
var oModel = new sap.ui.model.odata.ODataModel( "../TEST_ODATA.xsodata",true);
oTable.setModel(oModel);
oTable.bindRows("/sPath");
var oButton1 = new sap.ui.commons.Button({
text : "click",
style: sap.ui.commons.ButtonStyle.Accept,
press : function() {
document.getElementById("table").innerHTML = oTable.setVisible(false);
}});
index.html
<body class="sapUiBody">
<div id="table" style="margin-bottom: 20px"></div>
</body>
Error:
解決
This should just do it (no need for setting the innerHTML) :
press : function() {
oTable.setVisible(false);
}
他のヒント
just set your table to setVisible(false) and invalidate it so that ui5 will rerender it. this should be enough.
oTable.setVisible(false);
oTable.invalidate();
and remove your:
document.getElementById("table").innerHTML = ...
I have no idea what sapui5 is or where oTable
comes from, but it looks like your problem is here:
document.getElementById("table").innerHTML = oTable.setVisible(false);
You're setting the HTML inside the #table element to the return value of of the setVisible method.
I imagine you want one (or both) of:
document.getElementById("table").innerHTML = '';
oTable.setVisible(false);
Recommendation if you want to hide an element would be to style it as such:
document.getElementById("table").className = 'hidden';
and:
.hidden { display: none; }
Or if you want to remove an element:
var table = document.getElementById("table");
table.parentNode.removeChild(table);
use this
document.getElementById("table").style.display = "none";
instead of this:
document.getElementById("table").innerHTML = oTable.setVisible(false);