I am totally new to Lightning, and I come from a JavaScript background. This is what I have so far.

<aura:attribute name="Packages" type="Map" default="{p1: {name: 'Package 1', price: '2500 $'}, p2: {name: 'Package 2', price: '1500 $'}, p3: {name: 'Package 3', price: '500 $'}}" />
<aura:attribute name="PackageNames" type="String[]" default="['Package 1', 'Package 2', 'Package 3']" />
<aura:attribute name="currentPackage" type="Integer" default="0" />

My idea is to create a pagination component in Lightning. I am not sure what's the problem with using jQuery, but we are not allowed to do it. So I tried doing this:

  1. Create a map of maps, to replicate my Object Arrays. I used map here because, I need to give an id for each item in the map. - FAIL
  2. Create a String Array of the same kind of stuff.
  3. Create an Integer that points to the current item.
  4. Access the String Array with the Array index contained in the value of the Integer.

The last step is where the problem occurs. When I tried to access the Array Index statically, say:


It works perfectly fine. I get the Package 1 displayed in the screen. But if I wanna use something like either of the following:


I am getting the same error like this:



Isn't it a way to access the position dynamically using this method?

What I am trying to do:

I am trying to implement a pagination kind of structure here, where I have a currentPackage as the pointer to the index of the array of Packages. I don't have access to the Apex Controller, but I just have the access to Lightning Component, Lightning Controller, and the Style Sheet.

Let me know if I need to change my approach in a different way.

  • May be have a method in your Controller.js or helper.js file that returns the element with index "currentPackage" from the array. – prashanthkr Jun 6 '16 at 15:55
  • @prashanthkr Thanks. Isn't it not possible without going to Controller or Helper? – Praveen Kumar Purushothaman Jun 6 '16 at 15:55
  • One other way I can think of is not as clean -- use aura:iteration with indexVar and when indexVar==currentPackage, then display the element – prashanthkr Jun 6 '16 at 16:05
  • @prashanthkr Tried that, but it didn't work for Maps. Agree with you that it isn't cleaner. – Praveen Kumar Purushothaman Jun 6 '16 at 16:06
  • Aren't you trying to iterate an array? You wouldn't use an index for Maps right? – prashanthkr Jun 6 '16 at 21:29

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.