I am facing one issue with navigating to record from as href dont work in SF1 so i need to use controller for navigation e.g var sObjectEvent = $A.get("e.force:navigateToSObject");
but i need to get the Id of record from aura:iteraion
as current as i am getting undefined or only one id if i use input:hidden
, please help in this to solve.
Example code snippet:
<aura:component>
<aura:attribute name="OpptyList" type="Opportunity[]"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<div>
<aura:iteration items="{v.OpptyList}" var="oppty" >
<span>
<a href="" onclick="{!c.navigateToOppty}">{!oppty.Name}</a>
<!-- used id attribute, since aura:id is not working-->
<input:hidden value="{!oppty.Id}" id="opptyId"/>
</span>
<span>
<a href="" onclick="{!c.navigateToAccount}">{!oppty.Account.Name}</a>
<!-- used id attribute, since aura:id is not working-->
<input:hidden value="{!oppty.AccountId}" id="accountId"/>
</span>
</aura:iteration>
</div>
</aura:component>
controller.js
({
navigateToOppty: function (component) {
// it returns only first value of Id
var OpptyId = document.getElementbyId("opptyId").value;
var sObjectEvent = $A.get("e.force:navigateToSObject");
sObjectEvent.setParams({
"recordId": OpptyId,
"slideDevName": "detail"
});
sObjectEvent.fire();
},
navigateToAccount: function (component) {
// it returns only first value of Id
var AcctId = document.getElementbyId("AccountId").value;
var sObjectEvent = $A.get("e.force:navigateToSObject");
sObjectEvent.setParams({
"recordId": Acctid,
"slideDevName": "detail"
});
sObjectEvent.fire();
}
})