Sorry my english is not so good but I hope you will understand my problem. I made my data base with students names and other details, with all methods, post, get, delete and put. And its all working good. (I am new in programing,begginer, I dont know is it good way to do like I did it).
ime = name // prezime = lastname
var studentiDataStore = {
studenti: [],
postStudent: function(studijId, ime, prezime, brIndexa){
this.studenti.push({
id:this.studenti.length,
studijId: studijId,
ime: ime,
prezime: prezime,
brIndexa: brIndexa
});
return this.studenti[this.studenti.length-1];
},
getStudent: function(id){
if(id){
var targetIndex = -1;
for(var i=0; i<this.studenti.length; i++){
if(this.studenti[i].id===id){
targetIndex = i;
break;
}
}
if(targetIndex>-1){
return this.studenti[targetIndex];
} else {
return null;
}
} else {
return this.studenti;
}
}
},
Now i have this code to draw my students in HTMl
var displayStudents = function(){
var studenti = studentiDataStore.getStudent();
var htmlPresentation = [];
for(var i=0; i<studenti.length; i++){
htmlPresentation.push('<li class="list-group-item">'+ studenti[i].ime + " " + studenti[i].prezime+'</li>');
}
document.getElementById("mainContent").innerHTML = '<ul class="list-group">'+ htmlPresentation.join(" ") + '</ul>'
};
Now i have to make search/filter for my students, i tried to find answer but unsuccessful. My question is, how to make search filter, when I write first letter(and so on) it show me all names starting with that letter ? Thank you