В этой статье описывается метод моделирования таблицы JS. Поделитесь этим для вашей ссылки. Конкретные методы следующие:
<! Doctype html> <html> <head> <meta charset = "utf-8"> <title> list </title> <script> function list () {this.listsize = 0; this.pos = 0; this.datastore = []; // инициализируйте пустой массив, чтобы сохранить элемент списка this.clear = clear; this.find = find; this.toString = toString; this.insert = вставка; this.append = append; this.remove = удалить; this.front = front; this.end = end; this.prev = prev; this.next = Далее; this.length = длина; this.currpos = currpos; this.moveto = moveto; this.getElement = getElement; this.length = длина; this.contains = содержит; Функция Приложение (element) {this.datastore [this.listsize ++] = element; }; Функция найти (элемент) {for (var i = 0; i <this.datastore.length; i ++) {if (this.datastore [i] === element) {return i; }} return -1; } функция удалить (element) {var foundat = this.find (element); if (foundat! =-1) {this.datastore.splice (foundat, 1); this.ListSize--; возвратный элемент; // вернуть True, это было изначально, я изменил его на элемент} else {return false; }} function length () {return this.listsize; } function toString () {return this.datastore; } функция вставка (элемент, после) {var insertpos = this.find (после); if (insertpos! =-1) {this.datastore.splice (insertpos+1,0, элемент); this.listsize ++; вернуть истину; } else {return false; }} function clear () {delete this.datastore; this.ListSize = 0; this.pos = 0; this.datastore = []; } функция содержит (element) {for (var i = 0; i <this.datastore.length; i ++) {if (this.datastore [i] === element) {return true; }} вернуть false; } function front () {this.pos = 0; } function end () {this.pos = this.listsize-1; } function prev () {// if (this.pos> 0) { -this.pos; //}} функция Next () {// if (this.pos <this.listsize-1) {++ this.pos; //}} function currpos () {return this.pos; } функция moveto (pos) {this.pos = pos; } function getElement () {return this.datastore [this.pos]; }} var list = new list (); list.append ({name: 'xia guangcheng', sex: 'male'}); list.append ({name: 'jiang rongsheng', sex: 'male'}); list.append ({name: 'du qiang, sex:' male '}); list.append ({name: 'qiaohua', sex: 'nember'}); list.append ({name: 'fang yang', sex: 'male'}); list.append ({name: 'fang yang', sex: 'male'}); for (list.front (); list.currpos () <list.length (); list.next ()) {var item = list.getElement (); if (item.sex == 'fome') {list.remove (item); }} for (list.front (); list.currpos () <list.length (); list.next ()) {var item = list.getElement (); console.log (item.name); } </script> </head> <body> </body> </html>Я надеюсь, что эта статья будет полезна для каждого программирования JavaScript.