Cookie をグローバルな連想配列に保存するには、次のようにします。
var my_global_assoc_array = {};
$j('a.createCookie').click(function(e) {
var cookieName = "InsightsCookie";
var cookieValue = $j(this).attr("id");
$j.cookie(cookieName, cookieValue, {expires: 365, path: '/'});
// save just the value of the cookie
my_global_assoc_array[cookieName] = cookieValue;
// or save the whole cookie because you may want to know more about the cookie path, cookie expiration, etc
my_global_assoc_array[cookieName] = $j.cookie(cookieName);
});
その後、アソシエーション配列に収集されたものを反復処理できます。
for(var i in my_global_assoc_array)
console.log("cookie name = " + i + ", cookie value = " + i);
あなたの質問のこの部分について私は混乱しています:「トリッキーな部分は、Cookie の値が動的に作成されることです。」Cookie の値は my_global_assoc_array 内の単なる値なので、値が何であるかを事前に知る必要があるのはなぜですか?
アップデート
単一の Cookie に my_global_assoc_array のすべての値を含める場合は、set Cookie ルーチンでループを使用します。このようなもの:
var my_global_assoc_array = {};
$j('a.createCookie').click(function(e) {
var cookieName = "InsightsCookie";
var cookieValue = $j(this).attr("id");
// save all values of the cookie in an assoc array to uniqueify the list.
my_global_assoc_array[cookieValue] = 0;
// temporarily turn cookieValue into an Array, add all the cookieValues to it and
// use join to stringify it to a CSV value of the values.
cookieValue = new Array();
for(var i in my_global_assoc_array)
cookieValue.push(i);
cookieValue = cookieValue.join(',');
// store cookieValue which is now a CSV list of cookieValues
$j.cookie(cookieName, cookieValue, {expires: 365, path: '/'});
});