jQuery元数据,如何获取值?

问题描述:

我很难得到数据属性中的键的值。我正在使用jQuery元数据插件。jQuery元数据,如何获取值?

的jQuery:

jQuery.metadata.setType("attr", "data"); 

$('ul li').each(function() { 
    console.log($(this).metadata()) 
}); 

HTML

<ul> 
    <li data="{someKey:'someValue',anotherKey:'anotherValue'}">Some List Item</li> 
    <li data="{someKey:'someValue2',anotherKey:'anotherValue2'}">Some List Item 2</li> 
    <li data="{someKey:'someValue3',anotherKey:'anotherValue3'}">Some List Item 3</li> 
</ul> 

我输出对象,但不知道如何获得的价值。我试过$(this).metadata().someKey$(this).metadata('someKey'),现在我正在抓秸秆。

alt text

看起来像你想的:

myMeta = $(this).metadata(); 

然后你就可以访问myMeta.someKeymyMeta.anotherKey - 无论Meta键已设置。

+0

完美,谢谢! – jyoseph 2010-12-01 18:24:50