0

I have the following code, which successfully outputs data to to the product_slides array.

var product_slides = new Array();

Product.findAll({}, function(products) {
    $.each(products, function(i, product) {
        var product_slide = new Object();
        product_slide.title = product.name;
        product_slide.url = product.url;
        product_slides[i] = product_slide;
    });
});

When I view the contents with console.log(product_slides); in firebug's console it has the following format:

[
    {image = 'value', url = 'value'},
    ...
]

however, I need it to have the following:

[
    {image : 'value', url : 'value'},
    ...
]

which I believe may be JSON(?).

I'm still quite new to scripting, does anyone know how to swap those =s for :s ?

4

1 回答 1

0

在使 product_slide 成为对象而不是数组之后,在每个内部尝试此操作

product_slide{'image':product.name, 'url':product_url};

如果可行,请替换键的硬编码 val

于 2012-11-13T17:09:51.493 回答