Using jQuery.data to Store a List of Items

微信扫一扫,分享到朋友圈

Using jQuery.data to Store a List of Items

I’m working on a page where I need to associate a list of objects with a row of a table, and I’m using jQuery.

jQuery.data seems to just associate a piece of data with a key, whereas I need more like

id=4,setting=2
id=3,setting=1
...

I don’t know how long the list could be, and it could be empty.

Is there a sensible way of doing this?

You can store anything as jQuery data, so you could do this:

var myData = [ { id: 4, setting: 2 }, [ id:3, setting:1 ] };
$("#myitem").data("mydata", myData);

If you want to select something by id, you could do this:

var myData = {};
myData[4] = 2;
myData[3] = 1;
$("#myitem").data("mydata", myData);

Then you can access your settings like this:

var value = $("#myitem").data("mydata")[3]; // returns 1

微信扫一扫,分享到朋友圈

Using jQuery.data to Store a List of Items

Inter-bean notifications using Spring Events

上一篇

设置Python的wheel包自动根据系统安装不同的依赖

下一篇

你也可能喜欢

Using jQuery.data to Store a List of Items

长按储存图像,分享给朋友