Sie sind nicht angemeldet.

1

Dienstag, 2. Mai 2017, 12:16

How to get the Array/List count?

Hi

I have some problems with an actual array. I do not get the count of it.
Here is the code of the array and the function to read it.
I do get the product and color value out of it.

What is wrong there?

Quellcode

1
2
3
<array name="cart99">	<item name="i0" product="product1" color="red" url="123"/>	<item name="i1" product="product2" color="blue"/><item name="i2" product="product3" color="green"/>	</array>
	<action name="test">	trace(cart99.count);
		trace(array[cart99].item[i1].product);trace(array[cart99].item[0].color);	</action>


PS: How can i format the code properly?

Thanks
Sven

2

Dienstag, 2. Mai 2017, 16:17

Hi Sven,


Your array should be:
<array name="cart99">
<sub name="item0" product="product1" color="red" url="123" />
<sub name="item1" product="product2" color="blue" url="231" />
<sub name="item2" product="product3" color="green" url="321" />
</myarray >

array count of sub-items:
trace(array[cart99].sub.count);

get a value of array:
trace(array[cart99].sub[item0].product);

With a quick for() Action you can get all the infos of your array:

for(set(i, 0), i LE array[cart99].sub.count, inc(i),
txtadd(myTargetItem, 'item', get(i) );
trace(array[cart99].sub[get(myTargetItem)].product );
trace(array[cart99].sub[get(myTargetItem)].color );
trace(array[cart99].sub[get(myTargetItem)].url );
);

NOT tested, but should work...

Best,
Steve

Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »svb« (2. Mai 2017, 16:48)


Beiträge: 1 117

Wohnort: Poland, Europe

Beruf: krpano developer : virtual tours : the cms4vr owner

  • Nachricht senden

3

Donnerstag, 4. Mai 2017, 11:19

Or simply:


Quellcode

1
2
3
4
5
6
for(set(i,0),i LT array[cart99].sub.count,inc(i),  
  copy(n, array[cart99].sub[get(i)]);
  trace('product: ',get(n.product));  
  trace('color: ',get(n.color));  
  trace('url: ',get(n.url));
)



*thumbup*

Best regards
Piotr
Your own professional, online cloud tool for creating virtual tours - www.cms4vr.com

facebook page :: youtube :: wiki.cms4vr.com

cms4vr team *thumbsup*

4

Freitag, 5. Mai 2017, 02:06

Hi Piotr

thanks for that. I didn't know that you also have to tell krpano the sub element.

Ähnliche Themen