【发布时间】:2014-12-16 23:39:04
【问题描述】:
我想要具有不同类型部分的商店(杂货店、餐馆、健身房等)。它们对于数组中的对象是唯一的。例如,健身房将与杂货店有不同的部分。
var UserSchema = new Schema({
store: [
{
name: String,
section: Array,
}
],
});
我使用简单的 store: Array(在 UserSchema 中)来完成这项工作,但我将 store 更改为数组内的一个对象。如何推送到商店内的对象?
$scope.storeUpdate = function(){
Users.get({email:$scope.global.user.email}, function(user3) {
// Changing store.push to store.name.push gives the error: user3 not defined
// If in UserSchema the store: type: Array, then user3[0].store.push works fine
user3[0].store.section.push($scope.datStore.name);
user3[0].$update(function(response) {
// This just updates user changes on the webpage
Users.query({}, function(users) {
$scope.users = users;
$scope.global.user = response;
});
});
});
};
编辑:我应该只嵌入第二个架构吗?
【问题讨论】:
-
只能推送到一个数组,例如
user3[0].store.section.push...如果您进一步详细说明您的目标会有所帮助 -
当我执行 user3[0].store.section.push 时,它说“无法读取未定义的属性 'push'”
-
不清楚“我将存储更改为对象”是什么意思。它是代码中显示的与语句冲突的数组
-
Store 在数组中有一个对象。对此感到抱歉。
标签: javascript arrays angularjs mongoose