javascript - Why I cannot add field to a JS object? -
i'm programming node sequelize orm mysql. need add new field object sequelize returns on query, doesn't seems work.
category.find({ where: { id: req.params.id }, include: [item] }).success(function(category) { var items = category.items; var ci = category.items.map(function(item) { return item.id; }); delete category.items; // works category.item_ids = ci; // doesn't // category['item_ids'] = ci; // doesn't work res.send({ category: category, items: items }); });
object.isextensible
returns true on category
object, can't figure out how extend it
try this:
.success(function(category) { category = category.tojson(); // convert simple js object ... category.item_ids = ci; ... res.render(...); });
Comments
Post a Comment