function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
rahul mamtani 6rahul mamtani 6 

jquery and css not working while Iterating values in lightning?

Hi all,
I am creating a simple example with Jquery Mobile and lightning.When i am iterating my records using <aura:iteration> component Jquery and css is not working with it.But when i am using simple html code it is working fine.It is showing the records.
Here is my component code : -
<--------- Component---------------------------->
<aura:component controller="balluforce.fetchContacts">
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"></aura:handler>
    <aura:attribute name="contacts" type="contact"/>
    
    <div data-role="page" id="pageone">
            <div data-role="header">
                <h1>Company Contacts</h1>
            </div>
                <aura:iteration items="{!v.contacts}" var="con">
                    <div data-role="collapsible">
                        <h1>{!con.Name}</h1>
                        <p>
                            Email &nbsp;&nbsp; : &nbsp;&nbsp; {!con.email}
                            Phone &nbsp;&nbsp; : &nbsp;&nbsp; {!con.phone}<br/>
                        </p>
                    </div>
                </aura:iteration>
            </div>
    </div>
    </aura:component>
<============ App Code=============>
<aura:application >
    <link rel="stylesheet" href="/resource/balluforce__lightninglib/lightninglib/bootstrap.css"/>
    
    <balluforce:jquerymobilecomp />
    
    <script src="/resource/balluforce__lightninglib/lightninglib/jquery.js"></script>
    <script src="/resource/balluforce__lightninglib/lightninglib/bootstrap.js"></script>
    
</aura:application>
Is there any mistake in the code.Please help me.Thanks in advance.





 
Gaurav KheterpalGaurav Kheterpal
Change this line
 
<aura:attribute name="contacts" type="contact"/>
to
 
<aura:attribute name="contacts" type="contact[]" />
This should fix it.

If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others and improve the overall quality of Discussion Forums.

Gaurav Kheterpal
Certified Force.com Developer| Salesforce Mobile Evangelist| Developer Forums Moderator| Dreamforce Speaker



 
rahul mamtani 6rahul mamtani 6
@Gaurav
Records are coming no problem with Contact[] . My css is not applied and even jquery is not working when i use <aura:iteration> with simple html it is working fine.
For example : if i use like this Jquery and CSS is not working.
               <aura:iteration items="{!v.contacts}" var="con">
                    <div data-role="collapsible">
                        <h1>{!con.Name}</h1>
                        <p>
                            Email &nbsp;&nbsp; : &nbsp;&nbsp; {!con.email}
                            Phone &nbsp;&nbsp; : &nbsp;&nbsp; {!con.phone}<br/>
                        </p>
                    </div>
                </aura:iteration>
But if i use like this it is working.
                    <div data-role="collapsible">
                        <h1>Name</h1>
                        <p>
                            Email &nbsp;&nbsp; : &nbsp;&nbsp; Email
                            Phone &nbsp;&nbsp; : &nbsp;&nbsp; Phone<br/>
                        </p>
                    </div>
               
I think problem is with Iteration.


 
Gaurav KheterpalGaurav Kheterpal
This will happen if there's some problem with your static resource path for jQuery and Bootstrap CSS

Double check these
 
<script src="/resource/balluforce__lightninglib/lightninglib/jquery.js"></script>
    <script src="/resource/balluforce__lightninglib/lightninglib/bootstrap.js"></script>

If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others and improve the overall quality of Discussion Forums.

Gaurav Kheterpal
Certified Force.com Developer| Salesforce Mobile Evangelist| Developer Forums Moderator| Dreamforce Speaker

 
rahul mamtani 6rahul mamtani 6
@Gaurav
I have double check this and it is applied on other part of page.No problem with jquery and css they were loaded.It is not applied only on Iteration component.
Marc BourlonMarc Bourlon
@Rahul. Difficult to be sure since you didn't give us your js/css files, but what you describe is typical of a different DOM path in the Aura generated version. Check the css and jQuery path you use to find your elements in the DOM, and compare to the source of the page generated by Aura.
Ravi PRavi P
@Rahul, I am also facing same issue. Did you able to resolve this?