Sie sind nicht angemeldet.

1

Freitag, 3. April 2020, 09:39

Syntax Question

Hello, syntax question. How to find out the number of elements

<test a1="1" a2="2" a3="3" />

How to find out the number of "a№"?
How to get the value "a№" by its number?
How to get the name "a№" by its number?
*question*

2

Freitag, 3. April 2020, 12:31

Quellcode

1
2
3
4
5
6
// normal
trace(test.a1);

// dynamic
set(num,1);
trace(calc("test.a"+num));


but you probably mean something else...
getting the attribute name would be doable by javascript only.
but that its getting a bit complicated...

what do you want to do?

Tuur

Erleuchteter

Beiträge: 3 839

Wohnort: Netherlands

Beruf: Krpano custom coding / Virtual Tours / Photography / Musician / Recording engineer

  • Nachricht senden

3

Freitag, 3. April 2020, 13:19

Hi,

i was also trying to get this info some time ago..
https://krpano.com/forum/wbb/index.php?p…&threadID=17357

i think San7 wants to know the amount of attributes which is 3 in the example.

a1
a2
a3

and then call them for index number, name and value.
I might be wrong though..

Tuur *thumbsup*

4

Freitag, 3. April 2020, 14:20

Yes for example

<test a1="tt" a2="yy" a3="uu" />


trace (test [item] .count) --> 3 (3 elements)
trace (test [2]) --> yy(the second element contains yy)

trace (test [2].name) --> a2 (name of the second element)


But this is the wrong syntax, these are my fantasies *smile*



Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »San7« (3. April 2020, 15:02)


5

Donnerstag, 9. April 2020, 12:26

Hi,

please see the thread Tuur linked, there you see the answer:
https://krpano.com/forum/wbb/index.php?p…81170#post81170

Best regards,
Klaus

6

Donnerstag, 9. April 2020, 16:28

Klaus, thanks for the helpful example!
This works when there is a name:

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<test  name="test1"   a1="tt" a2="yy" a3="uu" />

<action autorun="onstart" type="Javascript"><![CDATA[
    var layer = krpano.get("test[test1]");
    var attributes = layer.getattributes();
    for (var i=0; i < attributes.length; i++)
    {
        var attrib = attributes[i];
        var value = layer[attrib];
	krpano.set("value", value);
	krpano.set("attrib", attrib);
	krpano.call("trace(attrib,=,value)");
    }
]]></action>


Can this be done if there is no name?

Quellcode

1
<test   a1="tt" a2="yy" a3="uu" />
*confused*

7

Donnerstag, 9. April 2020, 17:23

Quellcode

1
2
3
4
5
6
7
8
9
<test a1="tt" a2="yy" a3="uu" />

<action autorun="onstart" type="Javascript"><![CDATA[
	var el = krpano.get("test");
	var att = el.getattributes();
	for (var i=0; i < att.length; i++)  {
		krpano.trace(1, att[i] + ' = ' + el[att[i]]);
	}
]]></action>

8

Donnerstag, 9. April 2020, 17:25

It works! Thanks! *thumbsup* *thumbsup* *thumbsup*