Question

I have a component like tweetEnyo, created with enyo script. And based on its kind, i want to perform some action.

Is there a way to find the kind of a component created in enyo at runtime?

Was it helpful?

Solution

You should be able to access the kind property at runtime. Here's an example detecting the kinds of items selected:

http://jsfiddle.net/RoySutton/frTFK/

If you need to find it using the debugger, you can use the ID with the global enyo object's $ hash. e.g.:

enyo.$.app_myKind.kind

Not to steal the thunder from an upcoming blog post, but in the Chrome/Firefox web inspector, $0 is the last inspected element. So, enyo.$[$0.id].kind is the kind of the inspected item.

I did note that App had no kind associated with it in my example. Usure why that is.

Update: App was not declared with a specific kind and will fall back to the default kind for the parent, in this case Control. You can access that value with .defaultKind. Additionally you can specify kind using actual references to the kind (e.g. kind: enyo.Button), so .kind can't be relied on.

The correct way to get the name is to use .kindName, which will be the actual kind.

OTHER TIPS

From enyo website:

The base enyo.Control works much like an HTML tag. You can assign classes and attributes and give it a style. E.g.

new enyo.Control({content: "Hello From Enyo", classes: "foo",
    style: "color: red", attributes: {tabIndex: 0}}).renderInto(document.body);

So you could do:

new enyo.Control({content: "Hello From Enyo", classes: "foo",
                  style: "color: red", attributes: {tabIndex: 0, enyo:true}}).renderInto(document.body);

Which sets an attr for enyo to true and check for that. Anything that has that is enyo component.

Example: http://jsfiddle.net/NKTRe/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top