Fixed methods in conv(DRY)
This commit is contained in:
parent
f106116b8b
commit
d7ae149d05
@ -3,6 +3,7 @@ export class DropDown {
|
|||||||
#list;
|
#list;
|
||||||
#options;
|
#options;
|
||||||
#caret;
|
#caret;
|
||||||
|
#items;
|
||||||
|
|
||||||
constructor(options = {}) {
|
constructor(options = {}) {
|
||||||
this.#init(options);
|
this.#init(options);
|
||||||
@ -28,6 +29,9 @@ export class DropDown {
|
|||||||
|
|
||||||
this.#list = this.#element.querySelector('.list');
|
this.#list = this.#element.querySelector('.list');
|
||||||
this.#caret = this.#element.querySelector('.caret');
|
this.#caret = this.#element.querySelector('.caret');
|
||||||
|
|
||||||
|
const { items } = this.#options;
|
||||||
|
this.#items = items;
|
||||||
}
|
}
|
||||||
|
|
||||||
#initSelected(select) {
|
#initSelected(select) {
|
||||||
@ -224,28 +228,22 @@ export class DropDown {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addItem(item) {
|
addItem(item) {
|
||||||
const { items } = this.#options;
|
this.#items.push(item);
|
||||||
|
|
||||||
items.push(item);
|
|
||||||
this.#render();
|
this.#render();
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteItem(item) {
|
deleteItem(item) {
|
||||||
const { items } = this.#options;
|
let index = this.#items.indexOf(item);
|
||||||
|
|
||||||
let index = items.indexOf(item);
|
this.#items.splice(index, 1);
|
||||||
|
|
||||||
items.splice(index, 1);
|
|
||||||
|
|
||||||
this.#render();
|
this.#render();
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteItemAll() {
|
deleteItemAll() {
|
||||||
const { items } = this.#options;
|
this.#items.splice(0, this.#items.length);
|
||||||
|
|
||||||
items.splice(0, items.length);
|
console.log(this.#items);
|
||||||
|
|
||||||
console.log(items);
|
|
||||||
this.#render();
|
this.#render();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,8 +256,6 @@ export class DropDown {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getElement(number) {
|
getElement(number) {
|
||||||
const { items } = this.#options;
|
return this.#items[number];
|
||||||
|
|
||||||
return items[number];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ const dropdown = new DropDown({
|
|||||||
});
|
});
|
||||||
|
|
||||||
dropdown.addItem('ZAZ');
|
dropdown.addItem('ZAZ');
|
||||||
|
dropdown.addItem('LADA');
|
||||||
|
|
||||||
const dropdown2 = new DropDown({
|
const dropdown2 = new DropDown({
|
||||||
selector: '.cg-dropdown2',
|
selector: '.cg-dropdown2',
|
||||||
@ -34,6 +35,9 @@ const dropdown2 = new DropDown({
|
|||||||
});
|
});
|
||||||
|
|
||||||
dropdown2.addItem('LADA');
|
dropdown2.addItem('LADA');
|
||||||
|
// dropdown.deleteItemAll();
|
||||||
|
|
||||||
|
// dropdown2.deleteItem('MAN');
|
||||||
// dropdown2.selectIndex(3);
|
// dropdown2.selectIndex(3);
|
||||||
|
|
||||||
const dropdown3 = new DropDown({
|
const dropdown3 = new DropDown({
|
||||||
|
Loading…
Reference in New Issue
Block a user