Typescript array @property

Hi, i’m trying to show an array property to the editor in typescript.
My Code is:

the prefab atribute works prefectly but when i try with an array is not showing to the editor.

FormType is a unionType form typescript

@property({ type: [cc.String] })
mockForm: string[] = [];
3 Likes

Thank you @Ronsku
That’s works also with @property([cc.String) without {type : value}.
But i want to restrict the value that in the editor can be written.
Drop down will be awesome. I tryed with Enum type, but doesn’t works

I see, if you want dropdown then you need to use the enum like this:

const optionsEnum = cc.Enum({
  FIRST: 0,
  SECOND: 1,
  THIRD: 2
});

@property({ type: optionsEnum })
selection = optionsEnum.FIRST;
1 Like

Oh, i see.
image
image


So with normal enums doesn’t work but with the cc.Enum yes

Oh, you need to use cc.Enum to make it works!
image

@Ronsku really thx, You’d know how can i make a map with enum key and pairs with some type like string or other?

Something like this

1 Like

@amcgamer I don’t know how to make that. I would love if someone told me. That would be SO useful and it has been asked on this forums a few times before without solutions.

Let me know if you find out, I’ll do the same! :slight_smile:

1 Like

@jare, @slackmoehrle, Can you resolve this problem?

I’ll ask @jare to consider this thread in future releases.

That sounds nice, but would be awesome an answer or workaround to use nowadays. This it’s an extreme powerful tool and must be used.

Sorry, Map is not supported by now. The click events is just an array.

1 Like

Really thx @jare can you explain how to do the 3 property in a row using an array? I tryed to create a class that have only 3 properties or an interface and make an array of this type but doesn’t work. Can you bring us any solution?

It is implemented in Editor. You can create an inspector plugin to display a component, but it’s complicated. See http://docs.cocos2d-x.org/creator/manual/en/extension/extends-inspector.html

Thank you @jare seems will be useful. I hope map and extensions will be better supported in the next releases. Nice Job!!