2

I'm trying to loop a list of sObject fields and displaying the fields as column in a table.

In Visualforce, we could bind an sObject field like value="{!Contact[fieldName]}". But I'm unable to make this happen in a Lightning Component.

I'm trying to output my field data like this:

<aura:iteration items="{!v.contactColumns}" var="col">
<td>
<ui:outputText value="{!'contact.' + col.fieldName}"></ui:outputText>
</td>
</aura:iteration>

But it is displaying Empty output, without any value.

Am I doing it wrong in preparing dynamic field value binding for ui:outputText in above code?

Ive even tried using force:outputField without any luck and same empty value output:

<force:outputField value="{!'contact.' + col.fieldName}" />
  • everything is case sensitive. are you sure your field names are correct? For example col.fieldName is not the same as col.fieldname. Without seeing your actual code (and js controller) I can't really help. – Ross Bassett Oct 18 '16 at 19:02
  • Also, i'm not sure what you're trying to do with the value="{!'contact.' + col.fieldName}". is that .contact for dynamic binding, or display purposes? Please post all relevant code. – Ross Bassett Oct 18 '16 at 19:05
  • Yes my bad, i ll add full code in my post. – VarunC Oct 18 '16 at 19:06
  • Unlike visualforce, you cannot have dynamic field binding in LC.Check this answer out it might help – Praveen Oct 18 '16 at 19:35
  • @Praveen - Thanks a lot man, that is exactly the trick I was missing, I'm able to get the issue resolved now. Making Iteration loop over a sub component and that subcomponent init handler populating output value made the values populate in my component. If you could point that out in Answer, I could mark that as an accepted answer then :-) – VarunC Oct 18 '16 at 20:23