Calling a compontent value in a JS query

Hello I am trying to do something that seems so simple and yet I cannot achieve it.

I have a transformer, called currentItem, which converts several inputs into an object, like this:

let currentItem = {
  quantity: {{qtyInput.value}},
  weight: {{weightInput.value}},
  width: {{wInput.value}},
  length: {{lInput.value}},
  height: {{hInput.value}},
  stackable: {{stackable.value}},
}

return currentItem

That seems to work. Then I have a table which I want to use as temporary, where I am going to add several items before saving it to the database.

I want to push the currentItem value to the table.value, which I already set to be "from array". I am trying:

table1.value.push(currentItem.value)

But the query doesn't seem to recognize either values. What am I doing wrong? What is the correct way to do this?

You can't interact with a table using push. You need to set the data source. You can use a "variable" that is an array (used to be called "temporary state").

Thanks Matt, I was trying that before, now I know that its the correct wat. But, still, not working: here is my code:

items.value.push(currentItem.value)

I run it and nothing happens. Variable still shows the following:
image

The items transformer seems to be OK:
image

You don't use push there either. You need to use items.setIn or items.setValue

couple more things

  • I didn't see any mutations of the input data in your transformer. If you put the components in a form you can just use form1.data to get an object. Then you don't need the transformer
  • you can use push on an arrays you define in a js query; let arr = [];
1 Like

I think it is now working correctly, THANKS!!

This is what I did:

items [VARIABLE]:
initial value []

pushItem[JS QUERY]:

await items.setIn([items.value.length], itemDetails.data)

where itemDetails is a form.

THANKS

1 Like

No problem. :slight_smile: One more thing I like to enable in js query when using setValue or setIn (I'm not 100% sure setIn is impacted like setValue; seems like it)... is "Keep variable references inside the query in sync with your app". Note this may cause performance issues depending on your app.

1 Like

Great, thanks Matt!

1 Like