Comments (1)
It might not hurt to show a more complicated example as well. Say you are looping through an array of data and you don't know what fields are present and you are building a table from the data. You might do something like this. Assuming you have an array of objects and each object has the same properties, but since you are making a generic html element, you don't know in advance what those properties are.
const unknownProps = Object.keys(dataSource[0]);
return
<table>
<thead>
<tr>
{ unknownProps.map( p => {
return (<th>{p}</th>);
});
}
</tr>
</thead>
<tbody>
{
dataSource.map( data => {
return (
<tr>
{
unknownProps.map( p => {
return { <th>{data[p]}</th>);
})
}
</tr>
)
});
}
</tbody>
</table>
I think that is right. Had to cut down my code to make it even more generic but that should build you a table whether your data looks like { first: 'Jane', last: 'Doe' }
or { city: 'Beverly Hills', state: 'California', zip: '90210' }
with the property names as the table header.
from stencil-site.
Related Issues (20)
- Clock example no longer works HOT 1
- Doc v3 : componentDidUnload missing HOT 3
- Docs: Missing space in code comment for https://stenciljs.com/docs/reactive-data HOT 1
- Redux docs page should be updated to use Redux Toolkit examples HOT 2
- The document home page has a bug HOT 2
- forceUpdate in documentation HOT 1
- Dependency Dashboard
- bug: Issue consuming components in an Angular 16 Project HOT 5
- `@Watch()` could have an example using a `@State()` in the documentation HOT 3
- Missing content in styleUrls docs HOT 2
- Docs: stencil-library reference HOT 1
- missing documentation for Angular 17's standalone mode HOT 1
- test bug HOT 1
- NextJS Integration Example with app router HOT 1
- testing automation - needs doc
- testing automation
- React Integration - the build doesn't include web component files HOT 4
- Docs should show @stencil/react-output-target is a dev dependency
- Youtube guide to use stencil with React and Angular doesn't work HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stencil-site.