1

What is the correct way to default another attributes when declaring object[]?

This:

<aura:attribute name="foo" type="object[]" 
      default="[
        {
          'title': 'Account Name',
          'value': {!v.Account.Name}
        },
        {
          'title': 'Contact Email',
          'value': {!v.Contact.Name}
        }
      ]"/>

Or this:

<aura:attribute name="foo" type="object[]" 
      default="{![
        {
          'title': 'Account Name',
          'value': v.Account.Name
        },
        {
          'title': 'Contact Email',
          'value': v.Contact.Name
        }
      ]}"/>

Won't compile with error Cannot mix expression and literal string in attribute value, try rewriting like {!'foo' + v.bar}

This will compile but will won't get parsed at runtime:

<aura:attribute name="foo" type="object[]" 
      default="[
        {
          'title': 'Account Name',
          'value': v.Account.Name
        },
        {
          'title': 'Contact Email',
          'value': v.Contact.Name
        }
      ]"/>

Of course it works fine with statis references:

<aura:attribute name="foo" type="object[]" 
          default="[
            {
              'title': 'Account Name',
              'value': 'Buzz'
            },
            {
              'title': 'Contact Email',
              'value': 'foo@baz.qux'
            }
          ]"/>

I can always do this via JS on init, but I would rather not to.

  • Did you ever find an answer for this. I am in same situation... – user28452 Nov 27 '17 at 10:41
  • @user28452 sorry no, ended up using different pattern in the app. Still, would be useful to know. – dzh Nov 27 '17 at 22:46
  • Here is the answer from the community that I received and it worked! salesforce.stackexchange.com/questions/200106/… – user28452 Nov 28 '17 at 2:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.