Reputation: 622
I have this function to add key in a data with k="Toto"
$Root = $("#" + n); $Root.data("TFO", $.extend({ k: v }, $Root.data("TFO")));
But when I see $Root.data("TFO")
I get k
instead of the value in k
How can I do it?
Upvotes: 1
Views: 672
Reputation: 24638
Try this:
var obj = {};
obj[ k ] = v; //<--------- VALUE of k will be used here & NOT k
$Root = $("#" + n);
$Root.data("tfo", $.extend(obj, $Root.data("tfo")));
//or $Root.data()['tfo'] = $.extend( obj, $Root.data('tfo') );
Upvotes: 1
Reputation: 622
Sorry, I change my resarch on google and find this then result
function AddK($r, k, v) { var options = {}; options[k] = v; $r.data("TFO", $.extend(options, $r.data("TFO"))); }
Upvotes: 0
Reputation: 7666
Looks like no matter what is the case in your data-TFO
attribute you have to access it in lower case: $Root.data("tfo")
Upvotes: 0