且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在循环中创建命名的javascript对象

更新时间:2023-11-02 23:49:04

你已经过时了。您可以使用对象文字符号和括号表示法。

You are way over complicating this. You can just use object literal notation and bracket notation.

function getRegions(data) {
    var result = {};
    $.each(data, function (i, country) {
        result[data[i].Country] = {
            tooltip: 'Test',
            attr: {
                fill: data[i].Color
            }
        };
    });
    return result;
}