I am currently creating a list where you can add and remove elements while specifying the count of each added element.
I have included all elements in my data: Example:
[
{
"rowID": "21",
"rowAnzahl": 1,
"elementID": "127",
"elementName": "Element 4"
},
{
"rowID": "22",
"rowAnzahl": 1,
"elementID": "109",
"elementName": "Element 3"
},
{
"rowID": "",
"rowAnzahl": "",
"elementID": "106",
"elementName": "Element 1"
},
{
"rowID": "",
"rowAnzahl": "",
"elementID": "112",
"elementName": "Element 2"
}
]
Then I added two computed properties:
elements: function() {
return this.testData.filter(function(e) {
return e.rowID
})
},
unusedElements: function() {
return this.testData.filter(function(e) {
return !e.rowID
})
},
Afterwards, I implemented the following methods:
methods: {
addElement: function(index) {
var item = this.testData[index];
item.rowID = 'new' + this.rowCount++;
item.rowAnzahl = 1;
},
removeElement: function(index) {
var item = this.testData[index];
item.rowID = '';
item.rowAnzahl = '';
}
},
Now, I am facing an issue:
The index starts at 0 for my properties unusedElements and elements... However, since I require the index number for adding or removing the element, it is causing issues. Is there a way to filter the method by my elementID? Alternatively, can I set the elementID as the index number?
Thank you!