javascript - 将变量取消引用为其值以在另一个函数javascript中使用

标签 javascript jquery hashtable

function get_event_ids_from_dom()
{
    var event_ids = {};
    $.each(
    $("td.ms-cal-defaultbgcolor a"),
        function(index,value){
             var str = new String(value); 
             var id = str.substring(str.indexOf('=')+1,str.length);
             if(typeof(event_ids[id]) == "undefined")
             {
                event_ids[id] = this;
            }
            else
            {
                **event_ids.id.push(this);**

            }
        }
     )
        return event_ids;
}

在上面的 javascript 中,event_ids 是一个哈希表。我正在尝试为该哈希表分配值。

可以使用“hashtable.key.push(value)”向哈希表添加多个值。我正在尝试使用 event_ids.id.push(this);在上面的代码中。

我已在代码中将“id”声明为变量。问题是,我无法将变量“id”取消引用为其值。

这在 jquery/javascript 中可能吗?

哈希表的使用示例:

event_ids = {};
event_ids["1"]= 'John';
event_ids.1.push('Julie');

上面的例子会将 john 和 julie 添加到哈希表中。

最佳答案

试试这个:

function get_event_ids_from_dom() {
    var event_ids = {};
    $.each(
        $("td.ms-cal-defaultbgcolor a"),
        function(index,value){
            var str = value.toString(); 
            var id = str.substring((str.indexOf('=') + 1), str.length);
            if(typeof(event_ids[id]) == "undefined") {
                event_ids[id] = [];
            }
            event_ids[id].push(this);
        });
    return event_ids;
}

请注意,object["id"]object.id 相同,而 object[id] 则不同。

关于javascript - 将变量取消引用为其值以在另一个函数javascript中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6455428/

相关文章:

javascript - 防止除弹出窗口及其内容外的所有元素滚动

jquery - 检测滚动到 DIV 的底部

c# - .net 中的 HashTable/Dictionary 实现选择了哪种类型的冲突解决方案?

javascript - 单击导航栏元素后如何防止重新加载单页应用程序?

php - 伪随机 URL 生成

javascript - 在另一个 javascript 文件中调用 javascript 函数而不包含 include

c - 如何将值插入哈希表上的链接列表成员

javascript - 具有标准的 Flowtype 无法加载插件 flowtype--parser

jquery - 滚动时缩小 Logo

c++ - 使用哈希表构建符号表