开发者

How to attach custom data to elements?

开发者 https://www.devze.com 2023-03-30 07:08 出处:网络
Is there any way to attach custom data to elements? Kind of like the $.data() function in jQuery? I know you can subclass and element and add custom parameters, but it would be an overkill to create c

Is there any way to attach custom data to elements? Kind of like the $.data() function in jQuery? I know you can subclass and element and add custom parameters, but it would be an overkill to create custom class just to add a si开发者_C百科ngle custom parameter.


If I understand your question....

You can create new properties on any given object at runtime using syntax like this:

myObject['newProperty'] = 'somevalue';

I'm not sure I'd recommend it in most situations.


I'm not entirely sure I understand your question, but would making your element a dynamic class satisfy your requirements?


In Flex the ItemRenderer class (or DataRenderer) has a data property filled when it's instanciated by a Flex control with a dataProvider (such as List or DataGrid).


If your elements aren't dynamic, you can create Dictionary and use elements as a key to put any object with properties there:

var extraInfo:Dictionary = new Dictionary();
extraInfo[element1] = { tag : "Quick & dirty" };
// or
extraInfo[element2] = new ElementProperties("More solid approach");
0

精彩评论

暂无评论...
验证码 换一张
取 消