11import { defineComponent , ref , shallowRef } from 'strve-rv' ;
22import { buildData } from './data.js' ;
33
4- const Main = defineComponent ( ( ) => {
5- const selected = ref ( ) ;
6- const rows = shallowRef ( [ ] ) ;
7-
8- function setRows ( update = rows . value . slice ( ) ) {
9- rows . value = update ;
10- }
11-
12- function add ( ) {
13- rows . value = rows . value . concat ( buildData ( 1000 ) ) ;
14- }
4+ const selected = ref ( ) ;
5+ const rows = shallowRef ( [ ] ) ;
6+ function setRows ( update = rows . value . slice ( ) ) {
7+ rows . value = update ;
8+ }
159
10+ const TbodyComponent = defineComponent ( ( ) => {
1611 function remove ( id ) {
1712 rows . value . splice (
1813 rows . value . findIndex ( ( d ) => d . id === id ) ,
@@ -25,6 +20,31 @@ const Main = defineComponent(() => {
2520 selected . value = id ;
2621 }
2722
23+ return ( ) => (
24+ < tbody >
25+ { rows . value . map ( ( { id, label } ) => (
26+ < tr class = { id === selected . value ? 'danger' : '' } key = { id } >
27+ < td class = 'col-md-1' > { id } </ td >
28+ < td class = 'col-md-4' >
29+ < a onClick = { ( ) => select ( id ) } > { label } </ a >
30+ </ td >
31+ < td class = 'col-md-1' >
32+ < a onClick = { ( ) => remove ( id ) } >
33+ < span class = 'glyphicon glyphicon-remove' aria-hidden = 'true' > </ span >
34+ </ a >
35+ </ td >
36+ < td class = 'col-md-6' > </ td >
37+ </ tr >
38+ ) ) }
39+ </ tbody >
40+ ) ;
41+ } ) ;
42+
43+ const Main = defineComponent ( ( ) => {
44+ function add ( ) {
45+ rows . value = rows . value . concat ( buildData ( 1000 ) ) ;
46+ }
47+
2848 function run ( ) {
2949 setRows ( buildData ( ) ) ;
3050 selected . value = undefined ;
@@ -118,33 +138,7 @@ const Main = defineComponent(() => {
118138 </ div >
119139 </ div >
120140 < table class = 'table table-hover table-striped test-data' >
121- < tbody
122- onClick = { ( event ) => {
123- const el = event . target ;
124- const id = Number ( el . closest ( 'tr' ) . firstChild . textContent ) ;
125- if ( el . matches ( '.glyphicon-remove' ) ) {
126- remove ( id ) ;
127- } else {
128- select ( id ) ;
129- }
130- return false ;
131- } }
132- >
133- { rows . value . map ( ( item ) => (
134- < tr class = { item . id === selected . value ? 'danger' : '' } key = { item . id } >
135- < td class = 'col-md-1' > { item . id } </ td >
136- < td class = 'col-md-4' >
137- < a > { item . label } </ a >
138- </ td >
139- < td class = 'col-md-1' >
140- < a >
141- < span class = 'glyphicon glyphicon-remove' aria-hidden = 'true' > </ span >
142- </ a >
143- </ td >
144- < td class = 'col-md-6' > </ td >
145- </ tr >
146- ) ) }
147- </ tbody >
141+ < component $is = { TbodyComponent } />
148142 </ table >
149143 < span class = 'preloadicon glyphicon glyphicon-remove' aria-hidden = 'true' > </ span >
150144 </ fragment >
0 commit comments