First, I'm going to assume you're running the above code in a Server side controller and passing the results to your component. It's not clear if you're wanting to define a Type attribute for an Object's variable, but it sounds as though you do. I think there are two references that will answer all of your questions and point you in the right direction.
The way to do this is via a server side controller since the code you've posted won't run client side. See Working with Salesforce Records in the Lightning Component Developer Guide and I think you'll also find some of the links at the bottom of that page helpful to you too.
You'll notice the below code uses the aura:attribute
to set an object type.
<aura:component controller="MyObjController"/>
<aura:attribute name="myObjects" type="namespace.MyObj__c[]"/>
<aura:iteration items="{!v.myObjects}" var="obj">
{!obj.Name}, {!obj.namespace__myField__c}
</aura:iteration>
You'd need to pass a different type into your code and use set:attribute
to then provide the attribute's name
and type
to change it dynamically. See aura:set in the documentation for more on how to do this, including with arrays that contain an object and it's fields (object fields being what seems to be more relevant to your question).
You'll still need to have a server side controller that contains the results of your Apex schema describe calls to pass the type
in an @AuraEnabled
method to your component if you're doing this dynamically as implied by the code you've provided. You could also use typeof
rather than complete schema calls where appropriate. I wouldn't want to rely on JS for this.