0

在这种情况下,我希望日志输出anythingmetaData[price]但我有一个错误告诉我metaData[price]未定义。

function getMetaData(item) {
    var metaData = new Object();
    metaData[name] = $(item).siblings('.itemModalHolder').find('.item_name').text();
    metaData[price] = "anything";
    console.log(metaData[price]);
    return metaData;
}
4

1 回答 1

7

您需要引用对象键:

metaData['name'] = $(item).siblings('.itemModalHolder').find('.item_name').text();
metaData['price'] = "anything";

或更简洁的语法

metaData.name  = $(item).siblings('.itemModalHolder').find('.item_name').text();
metaData.price = "anything";
于 2013-06-28T20:56:43.027 回答