【发布时间】:2015-12-23 02:58:49
【问题描述】:
我正在使用 SailsJS、AngularJS 和 MongoDB 构建应用程序,我很困惑如何将数据数组插入到对象中。这是我的架构示例
Asset.js
module.exports = {
schema : false,
attributes: {
product : { model : 'Product' },
store : { model : 'Store' },
key : { type : 'object' }
}
};
这是我的视图表单
<tbody ng-repeat="attr in product.category.templateAttribute" ng-show="{{product.category.name == 'custom'}}">
<tr>
<td>
<input class="form-control input-small" value="{{attr.attribute}}" />
</td>
<td>
<input class="form-control input-small" placeholder="name" ng-model="product.attributes[attr.attribute].name" />
</td>
<td>
<input class="form-control input-small" placeholder="add price" ng-model="product.attributes[attr.attribute].additionalPrice" />
</td>
</tr>
<tr>
<td colspan="3">
<file-uploader class="form-control input-small"
max-size="25000"
result-model="product.attributes[attr.attribute].file">
</file-uploader>
</td>
</tr>
</tbody>
这是我的查询
ProductCustomAsset.create({
product : product.id,
store : product.store,
key : product.attributes
})
.then(function(){
next();
})
.catch(function(error){
next(error);
});
我的查询有什么问题,没有错误,但只有键数组没有对象。
我希望结果是这样的
{
"_id" : 5,
"product" : 3,
"store" : 2
"key": [
{
"attribute": "xxxxxxx",
"name": "book",
"additionaPrice": "xxxx",
"file": "xxxx" ,
}
]
}
【问题讨论】:
-
您的查询应该搜索是否存在产品 User.findOne("product").exec(function (err, product) { product.key.push({ /* 不管 / }) ; product.save(function (err) { / all done */ }); }); stackoverflow.com/questions/18161056/…
标签: angularjs mongodb sails.js