Newer Version Available

This content describes an older version of this product. View Latest

JSON Models

Use a JSON model to read your initial component data in Aura from a JSON resource.

To initialize your component from a more dynamic source, such as a record, use an Apex model instead.

Wiring Up the Model

You can explicitly declare a model in the aura:component tag by including a model system attribute with the format model="js://<namespace>.<componentName>". This enables reuse of a model from another component. For example, this component uses the model for auradocs.sampleComponent.

1swfobject.registerObject("clippy.codeblock-0", "9");<aura:component model="js://auradocs.sampleComponent

If you explicitly declare a model system attribute, it takes precedence over a model in the component bundle.

A component can only have a JSON or Apex model, but not both.

Note

Sample JSON Model

Here is a sample JSON model.

1swfobject.registerObject("clippy.codeblock-1", "9");{
2    "bool" : true,
3    "num" : 5,
4    "str" : "My name is JSON",
5    "list" : []
6}

Don't use null for model values. Use [] for an empty array, "" for an empty string, or zero for a number. This enables the framework to determine which type of value wrapper to initialize. Due to a current limitation, don't use {} for an empty object.

Note

Accessing the Model in Markup

Here is simple usage of a model in the markup of a component.

1swfobject.registerObject("clippy.codeblock-2", "9");<-- This component uses an auto-wired model
2    as this aura:component tag has no model system attribute -->
3<aura:component>
4    boolean: {!m.bool}   
5    number: {!m.num}   
6    string: {!m.str}   
7    list length: {!m.list.length}
8</aura:component>