웹 개발에 익숙하지 않아서 해결할 수없는 문제가 발생했습니다. 지금까지 MEAN -Stack으로 시작했고 다음과 같은 문제가 발생했습니다.MEAN-Stack은 mongoose와 함께 MongoDB에 배열을 저장합니다.
각도 js 컨트롤러의 슬라이더에 대한 배열 구조가 있습니다. 이 배열 구조에서 내 데이터베이스에 몇 가지 값을 저장하려고합니다.
각도 JS 컨트롤러 내가 제목의 값 및 경고
를 들어 각 경고의 무게을 저장하려면, 위의 코드 조각에서
$scope.alerts = [
{ id: 1,
title: 'CustomerCount',
value: 1,
weight: 30,
options: {
showTicks: true,
hidePointerLabels: true,
hideLimitLabels: true,
stepsArray: [
{ value: 1, legend: '<10' },
{ value: 2, legend: '<50' },
{ value: 3, legend: '<250' },
{ value: 4, legend: '<500' },
{ value: 5, legend: '>500' }
]
}
},
{ id: 2,
title: 'CustomerSatisfaction',
value: 3,
weight: 40,
options: {
showTicks: true,
hidePointerLabels: true,
hideLimitLabels: true,
stepsArray: [
{ value: 1, legend: '<10' },
{ value: 2, legend: '<50' },
{ value: 3, legend: '<250' },
{ value: 4, legend: '<500' },
{ value: 5, legend: '>500' }
]
}
}
];
스 니펫 이 목적은, 나는 같은 각도의 컨트롤러에 다음 스 니펫을 가지고있다.
// Create new Article object
var article = new Articles({
title: this.title,
alert: this.alert,
});
,210
지금까지 내가이 조각은 server.model.js 파일에 정의 된 다음 스키마를 사용하여 내 데이터베이스에 새 문서 항목을 만들 않습니다 이해
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
/**
* Article Schema
*/
var ArticleSchema = new Schema({
created: {
type: Date,
default: Date.now
},
user: {
type: Schema.ObjectId,
ref: 'User'
},
alert: [{ value: Number, weight: Number, title: String }]
});
mongoose.model('Article', ArticleSchema);
하지만 내 문제는 지금은 빈을 절약 할 수 있다는 것입니다 MongoDB에 배열.
아래 제시된 용액이 용액으로 이어진다. 그것은 주목해야한다
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
/**
* Article Schema
*/
var ArticleSchema = new Schema({
created: {
type: Date,
default: Date.now
},
user: {
type: Schema.ObjectId,
ref: 'User'
},
alerts: []
});
// Create new Article object
var article = new Articles({
title: this.title,
alerts: this.alerts,
});
원하는 솔루션을 제공합니다!
모델에서'save()'메소드를 어디에서 호출합니까? 즉 article.save()입니까? – chridam
나는 여기에 나열되지 않은 내 article.server.controller.js 파일에 있습니다. 아래에 제공된 codeGig와 비슷합니다. – danielkr