Help with indexing flex repeater instances component dataset?

I obviously don’t know enough about dataset and attributes of components, so I need some help.

I have a flex repeater with the path set to a view with a checkbox. I have a button that is intended to step through the text boxes and see which ones are selected. If I look at the Instances parameter on the flex repeater with logger messages:

Instances = self.getSibling("FlexRepeater_Obj").props.instances
logger.info("list" + str(Instances))
logger.info("list[0]" + str(Instances[0]))	

i get:

  list<ArrayWrapper>: [<ObjectWrapper>: {u'text': u'dan', u'selected': False}, 
  <ObjectWrapper>: {u'text': u'jill', u'selected': False}, <ObjectWrapper>: 
  {u'text': u'NOTA', u'selected': False}]

  list[0]<ObjectWrapper>: {u'text': u'dan', u'selected': False}

Now what I want to do is look at each column in Instances[0]. I assume I would index this at Instances[row][column]. However, when I try to look at Instances[0][0] like this:

Instances = self.getSibling("FlexRepeater_Obj").props.instances
logger.info("list" + str(Instances))
logger.info("list[0]" + str(Instances[0]))	
logger.info("list[0][0] " + str(Instances[0][0]))

i get an error on the last line:

list<ArrayWrapper>: [<ObjectWrapper>: {u'text': u'dan', u'selected': False}, 
   <ObjectWrapper>: {u'text': u'jill', u'selected': False}, <ObjectWrapper>:
   {u'text': u'NOTA', u'selected': False}]

list[0]<ObjectWrapper>: {u'text': u'dan', u'selected': False}

Error running action 'dom.onClick' on 
    View_001@C$0:1/root/Button_CastBallot: Traceback (most 
    recent call last): File "<function:runAction>", line 14, in runAction 
    KeyError:0

How do I reference the ‘selected’ column in each row to see if the value is true or false? I have tried toPyDataSet() and toDataSet() but neither helps.

Well, what might help clear the waters a bit, is that it isn’t a dataset. But a List of Objects with attributes. So you reference it that way.

Instances = self.getSibling("FlexRepeater_Obj").props.instances
logger.info("list[0].text" + Instances[0].text)
logger.info("list[0].selected" + str(Instances[0].selected))

So if you wanted to loop through the repeater and record which instances were selected, one way to do that is:


Instances = self.getSibling("FlexRepeater_Obj").props.instances
selInst = []
for instance in Instances:
    if instance.selected:
        selInst.append(instance.text)

And of course you could do that condensed into a comprehension if you wished as well

Instances = self.getSibling("FlexRepeater_Obj").props.instances
selInst = [instance.text for instance in Instances if instance.selected]
3 Likes

Thank you, perfect!