File tree Expand file tree Collapse file tree 2 files changed +22
-6
lines changed Expand file tree Collapse file tree 2 files changed +22
-6
lines changed Original file line number Diff line number Diff line change 12
12
< body >
13
13
< js-container >
14
14
< js-tag transform ="uppercase "> Data</ js-tag >
15
+
15
16
<!-- where the data comes from -->
16
- < js-provider id ="provider " origin ="http://localhost:8080/ " path ="aktek/sync " interval ="5 "> </ js-provider >
17
+ < js-provider id ="provider " origin ="http://localhost:8080/ " path ="aktek/area " interval ="5 "> </ js-provider >
17
18
18
- <!-- model -->
19
- < js-array id ="array " provider ="#provider "> </ js-array >
19
+ <!-- model, areas come from the body element -->
20
+ < js-array id ="array " provider ="#provider " select =" body " > </ js-array >
20
21
21
22
<!-- view -->
22
23
< js-tablebody id ="body " data ="#array ">
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ export class ArrayElement extends LitElement {
23
23
static get properties ( ) {
24
24
return {
25
25
provider : { type : String , reflect : true } ,
26
+ select : { type : String , reflect : true } ,
26
27
} ;
27
28
}
28
29
@@ -77,8 +78,22 @@ export class ArrayElement extends LitElement {
77
78
}
78
79
79
80
#providerObject( event ) {
80
- // Add the object to the data container
81
- this . #newdata. push ( event . detail ) ;
81
+ var data = event . detail ;
82
+ if ( this . select ) {
83
+ if ( data instanceof Object ) {
84
+ data = data [ this . select ] ;
85
+ if ( data === undefined ) {
86
+ throw new Error ( `Property "${ this . select } " not found in object` ) ;
87
+ } else if ( Array . isArray ( data ) ) {
88
+ this . #newdata = this . #newdata. concat ( data ) ;
89
+ } else {
90
+ this . #newdata. push ( data ) ;
91
+ }
92
+ }
93
+ } else {
94
+ // Add the object to the data container
95
+ this . #newdata. push ( data ) ;
96
+ }
82
97
}
83
98
84
99
#providerDone( ) {
@@ -96,7 +111,7 @@ export class ArrayElement extends LitElement {
96
111
97
112
// Copy over the data
98
113
this . #data = this . #newdata;
99
-
114
+
100
115
// Emit a change event if the data was modified
101
116
if ( modified ) {
102
117
this . dispatchEvent ( new CustomEvent ( EventType . CHANGE , {
You can’t perform that action at this time.
0 commit comments