If you want to delete all lines from a certain index, e.g. 6, you can do the following:
DELETE lt_data FROM 6 TO lines( lt_data ).
As result, your table will only hold the first 5 rows.
If you want to delete all lines from a certain index, e.g. 6, you can do the following:
DELETE lt_data FROM 6 TO lines( lt_data ).
As result, your table will only hold the first 5 rows.
[
{
"NodeId": 1,
"HierarchyLevel": 1,
"type": "folder",
"nodes": [
{
"NodeId": 2,
"HierarchyLevel": 2,
"type": "folder",
"nodes": [
{
"NodeId": 3,
"HierarchyLevel": 3,
"type": "category"
}
]
},
{
"NodeId": 4,
"HierarchyLevel": 2,
"type": "category",
"nodes": [
{
"NodeId": 5,
"HierarchyLevel": 3,
"type": "file"
}
]
}
]
},
{
"NodeId": 6,
"HierarchyLevel": 1,
"type": "folder",
"nodes": [
{
"NodeId": 7,
"HierarchyLevel": 2,
"type": "category"
}
]
}
]
My task was to get rid of every Node which has no subnodes of type file at the last level of the hierachy. So for this example the result I needed was an array containing only the nodes 1,2,4,5.
Of course in reality the nested structure was way more complex. My approach was a recursive function which checks every element’s type and nodes length property and calls itself if there are any subnodes. Also it is recommended to loop backwards through the array while deleting from it.
const removeEmptyNodes = nodes => {
for (let i = nodes.length - 1; i > -1; i--) {
const n = nodes[i]
//call function recursive to go deeper through the nested structure
if (n.nodes) removeEmptyNodes(n.nodes)
//remove element if it's not a file and has no subnodes
if (n.type !== 'file' && (!n.nodes || n.nodes.length === 0)) nodes.splice(i, 1)
}
}
// nodes contains the array data from above
removeEmptyNodes(nodes)
Button für das Kopieren einer Zeile hinzufügen.
<Table id="itemsTable" items="{oModel>/ITEMS}">
<columns>
<Column id="splitColumn" hAlign="Center" demandPopin="false">
<Text text="{i18n>SPLIT}"/>
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<Button press="onSplitPressed" id="SPLIT_ROW" icon="{= ${oModel>CUSTOM_ITEM} === true ? 'sap-icon://delete' : 'sap-icon://add'}"/>
</cells>
</ColumnListItem>
</items>
</Table>
Nur neu hinzugefügte Zeilen sollen auch wieder gelöscht werden dürfen, daher werden manuell hinzugefügte Zeilen markiert mit CUSTOM_ITEM = True;
Via Expression Binding wird dann das erforderliche Icon bestimmt.
onSplitPressed: function (oEvent) {
var oContext = oEvent.getSource().getBindingContext("oModel");
var path = oContext.getPath();
var oModel = oContext.getModel();
var oItems = oModel.getProperty("/ITEMS");
var index = path.substr(path.length - 1);
//selektiertes Item lesen
var oItem = oModel.getProperty(path);
//was soll passieren? Zeile hinzufügen oder entfernen?
if (oItem.CUSTOM_ITEM !== true) {
//Neues Item anlegen
var oNewItem = JSON.parse(JSON.stringify(oItem));
//Markiere neue Zeile, da nur diese auch wieder gelöscht werden darf
oNewItem.CUSTOM_ITEM = true;
// +1 weil Zeile soll ja nach der Aktuellen einfügt werden
index++;
oItems.splice(index, 0, oNewItem);
} else {
// Item löschen
oItems.splice(index, 1);
}
oModel.setProperty("/ITEMS", oItems);
},
If you downloaded a series there are often folders for each episode. Each episode folder often includes another folder called “Sample” with a short demo video file.
Series -> Season 01 -> Episode 01 -> Sample -> sample.mkv
To get rid of these you can use the “find” and “rm” command. To remove each sample folder with its content you have to use the remove command with an “-r”.
find -name "Sample" -exec rm -r "{}" \;