How to pass array from js to app connect
Please provide more details what and where are you trying to send.
spotsToAdd.forEach(spotId => {
const record = {
id: spotId,
spot: `Место ${spotId}`,
price: state.spotPrices[spotId] || 0
};
to create booking table in app connect
Looks to me some code is missing here. Don't you do anything like:
records.push(record);
inside the forEach
, which is missing from the code you pasted?
Anyway here it's explained how to access js values from App Connect:
Teodor, the solution dmx.app.set() that you mentioned is working only with single variable but I need array like [{ id: 5, spot: "Место 5", price: 1500 }, { id: 7, spot: "Место 7", price: 500 }....]
Try this post instead for direction:
Not sure what you mean here? You can store any value this way.
I don't want to store but just show in table this array . I tried but with no success . Can I use datastore with dmx.app.set ?
What exactly have you tried?
Please post the code and explain what is the issue. We need more details to be able to help you.
<table class="table">
<thead>
<tr>
</tr>
</thead>
<tbody id="d">
<tr>
<td>{{details.id}}</td>
<td>{{details.spot}}</td>
<td>{{details.price}} руб</td>
</tr>
</tbody>
</table>
<table>
</table>
</div>
</div>
<script>
function loadSpots() {
var booking_details = [{ id: 5, spot: "Место 5", price: 1500 }, { id: 7, spot: "Место 7", price: 500 }];
dmx.app.set('details', booking_details);
}
</script>
Your table code is wrong, it’s missing the repeat. It should be:
<table class="table">
<thead>
<tr></tr>
</thead>
<tbody id="repeat1" is="dmx-repeat" dmx-bind:repeat="details">
<tr>
<td>{{id}}</td>
<td>{{spot}}</td>
<td>{{price}} руб</td>
</tr>
</tbody>
</table>
Thank you so much