Within my database, there are 2 tables:
1- Element:
- ElementID
- ElementName
2- Methods:
- MethodID
- ElementID
- MethodData
There exists a one-to-many relationship between Elements and Methods,
I am retrieving the data from these tables using asp.net,
My goal is to transmit this data to my javascript, where various functions will be performed on it.
For example, looping through all elements, accessing each element's methods, and manipulating the method data.
Initially, I attempted to structure this using classes in JavaScript but ended up with excessive code,
Firstly defining 2 classes, for elements and methods, followed by 2 arrays - one for elements and the other for methods
Within the methods array, I included the following:
this.findByElementId = function(elementId) {
var result = [];
for (var i = 0; i < this.methods.length; i++) {
if (elementId === this.methods[i].methodElement) {
result.push(this.methods[i]);
}
}
return result;
}
Unfortunately, this implementation led to slow performance of my code.
Therefore, I am seeking guidance on how to more professionally represent this relational structure in JavaScript for optimized code efficiency.