Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions frameworks/keyed/alpine/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ <h1>Alpine-keyed</h1>
</div>
<table class="table table-hover table-striped test-data">
<tbody>
<template x-for="item of data" :key="item.id">
<tr :class="item.id === selected ? 'danger' : ''">
<template x-for="(item, idx) of data" :key="item.id">
<tr :class="item.selected && 'danger'">
<td class="col-md-1" x-text="item.id"></td>
<td class="col-md-4">
<a @click="select(item.id)" x-text="item.label"></a>
<a @click="select(idx)" x-text="item.label"></a>
</td>
<td class="col-md-1">
<a @click="remove(item.id)"
<a @click="remove(idx)"
><span
class="glyphicon glyphicon-remove"
aria-hidden="true"
Expand Down
9 changes: 6 additions & 3 deletions frameworks/keyed/alpine/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ window.app = function() {
this.data[i].label += ' !!!';
}
},
remove(id) {
const idx = this.data.findIndex(d => d.id === id);
remove(idx) {
this.data.splice(idx, 1);
},
run() {
Expand All @@ -45,7 +44,11 @@ window.app = function() {
this.data = buildData(10000);
this.selected = undefined;
},
select(id) { this.selected = id },
select(idx) {
if (this.data[this.selected]) this.data[this.selected].selected = false;
this.data[idx].selected = true;
this.selected = idx;
},
swapRows() {
const d = this.data;
if (d.length > 998) {
Expand Down