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 1212< body >
1313 < js-container >
1414 < js-tag transform ="uppercase "> Data</ js-tag >
15+
1516 <!-- 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 >
1718
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 >
2021
2122 <!-- view -->
2223 < 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 {
2323 static get properties ( ) {
2424 return {
2525 provider : { type : String , reflect : true } ,
26+ select : { type : String , reflect : true } ,
2627 } ;
2728 }
2829
@@ -77,8 +78,22 @@ export class ArrayElement extends LitElement {
7778 }
7879
7980 #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+ }
8297 }
8398
8499 #providerDone( ) {
@@ -96,7 +111,7 @@ export class ArrayElement extends LitElement {
96111
97112 // Copy over the data
98113 this . #data = this . #newdata;
99-
114+
100115 // Emit a change event if the data was modified
101116 if ( modified ) {
102117 this . dispatchEvent ( new CustomEvent ( EventType . CHANGE , {
You can’t perform that action at this time.
0 commit comments