Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Highlighted
Developer
Posts: 50
Registered: ‎11-15-2012
My Device: Q10
My Carrier: WIND
Accepted Solution

QML JavaScript Array join

It seems that coercing an array to string shows that it has the correct contents, but just .join(', ') does not work.  Is this supposed to work in QML?  Is there something else that replaces it?

 

I have the following code, which I create, push onto my navstack, and then call the newParticipant member:

 

 

Page {
   property variant participants: []

   function newParticipant(fn) {
      this.participants += [fn];
      participantLabel.text = "With: " + this.participants.join(', ');
   }

 

      Label {
         id: participantLabel

         text: "With: "
         textStyle {
            base: SystemDefaults.TextStyles.SubtitleText
         }
         verticalAlignment: VerticalAlignment.Center
         multiline: true
      }
}

Developer
Posts: 323
Registered: ‎05-07-2009
My Device: BlackBerry Z10, PlayBook, 9900
My Carrier: Telus

Re: QML JavaScript Array join

I haven't tested this.. but if the participants is really like a "true" JavaScript array I think the issue is with how you add items to the array.

 

Normally in JavaScript to add Item to an array you use .push(item)

 

so your function would be:

 

  function newParticipant(fn) {
      this.participants.push(fn);
      participantLabel.text = "With: " + this.participants.join(', ');
   }

 

so far as I know the "+=" is really only relivant when concatinating with strings.


PlayBook Apps: DataMine, Dots + Boxes, 5 Marbles
BlackBerry SmartPhone Apps: 5 Marbles Soon: **** (D.Z.A), ****Quest, **** Challenge, VaultCracker, DevBrowser, Radial****
Developer
Posts: 50
Registered: ‎11-15-2012
My Device: Q10
My Carrier: WIND

Re: QML JavaScript Array join

I started with .push, and that also didn't work.

Developer
Posts: 50
Registered: ‎11-15-2012
My Device: Q10
My Carrier: WIND

Re: QML JavaScript Array join

Turns out, properties in QML (v4) are not real JavaScript arrays, but sort of pretend to be.  They cannot be mutated.  The workaround is:

 

 

var tmp = property;

tmp.push(a);

property = tmp;