#How to bind button to iterate on a list

1 messages · Page 1 of 1 (latest)

zinc coyote
#

I have button and list.

I want that the button will move the list forward.

I tried: List1.selectedItem = List1.selectedItem +1

zinc coyote
#
  1. In addition I would like to get the index of current element using it as parameter to a Query.
zinc coyote
#

..

harsh sealBOT
#

Hi there! Sorry for the delay in response, we really appreciate your patience.
To start with, can you give me a sample of the type of data in your list?

zinc coyote
#

it's an array of jsons that I put inside the list (the regular one with images, and text)

#

The list elements handle the array fair & square in the List componnent, I just want to control the index that is shown

#

(My use case is to do some "tagging" for each element, via different buttons, and when the tag is occured, the list continue to the next element automatically

harsh sealBOT
#

Alright. Thank you for the explanation.

You can manually get the index of the currently selected element by using the
following:

const index = List1.listData.findIndex((el) => {
return el.id === List1.selectedItem.id;
});

You can then proceed to, for example, get the element next to the currently
selected element like so:

index = index +1;
return List1.listData[index]

Does this answers your question?

#

Alright. Thank you for the explanation.

You can manually get the index of the currently selected element by using the
following:

const index = List1.listData.findIndex((el) => {
return el.id === List1.selectedItem.id;
});

You can then proceed to, for example, get the element next to the currently
selected element like so:

index = index +1;
return List1.listData[index]

Does this answers your question?

zinc coyote
#

I want also to set it to the current List presentation

#

not only to get it

#

BTW I found that to get manually the elemnt I can use currentIndex

zinc coyote
zinc coyote
harsh sealBOT
#

Hi there!

Sorry for the late response. We really appreciate your patience.
I'm not sure I completely understand what you meant by "set the List item for
another index". Can you please elaborate so I can better help you?

zinc coyote
#

To control about which item will be shown in the list (i.e. when user click a button anew item in the list will shown- the next one)

zinc coyote
harsh sealBOT
#

I think that's a great idea! Please, show us what you intend 🙂

zinc coyote
#

Here is list and a button (Before)

#

Herer is the situation after clicking the button "show element 3"

#

(Element number 3 is on focus)

harsh sealBOT
#

I see! Can you tell me more about your use case and why you'd want to do this?

zinc coyote
#

(My use case is to do some "tagging" for each element, via different buttons, and when the tag is occured, the list continue to the next element automatically )

#

The "show element 3" is just to demonstrate the effect that i want to make happen.

harsh sealBOT
#

Would it be acceptable to instead filter the source data by these tags?

zinc coyote
zinc coyote
zinc coyote
harsh sealBOT
#

Hey! Sorry for the delay here. Could you elaborate what you mean in the last
message? What's returning a value of 0?

zinc coyote
#

When I running this -> with my list : const index = List1.listData.findIndex((el) => { return el.id === List1.selectedItem.id; });

#

I do it without decleration const index...but rather directly return this index

#

I try to update my mongodb with the selected item. This is my overall update code: { "$set": { "array.{{List1.listData.findIndex((el)=>{ return el.id === List1.selectedItem.id })}}.accepted": "checked" } }

#

but {{List1.listData.findIndex((el)=>{ return el.id === List1.selectedItem.id })}} keep returning '0'

harsh sealBOT
#

Would you be willing to get on a call to debug this?

zinc coyote
#

Sure (but only on call, cause i can't show the app) in which platform?

#

Here on discord?

harsh sealBOT
#

I can create a zoom link :) One moment

zinc coyote
#

Okay 🙂

harsh sealBOT
zinc coyote
#

40 min zoom 🙂

#

Jimmy, Can you share another zoom-link ? 🙂

zinc coyote
harsh sealBOT
#

Sent to you in DM :)

harsh sealBOT
#

We ended up rewriting the list to use the appsmith store so that it could be
manipulated after querying. We also discovered that the objects don't actually
have an id property, and that's why it was returning 0. After implementing these
changes and planning to add an id to the objects, the issue was resolved. Can
you confirm this @zinc coyote?

zinc coyote
#

I Confirm! I appreciate the professional and the precise support! In addition to resolve that issue, I learnt more than few things about how to debug to console, and optimize my queries to the db. Thanks Jimmy!

harsh sealBOT
zinc coyote
#

"Failed send feedback" - several times...