1
Compound.js를 사용하여 블로그를 만들려고합니다. 두 개의 테이블, "Category"및 "Post", 각 날짜 속성이 있지만 테이블을 생성 할 때 각 "새"보기에서 날짜 속성에 대한 입력 가진 양식을 ...Compound.js를 사용하여 컨트롤러의 속성을 업데이트하십시오.
작성일이 내 컨트롤러에서 자동으로 날짜 표시를 업데이트하고 싶습니다.
어떻게 만들 수 있습니까?
내 쉐마 :
var Category = describe('Category', function() {
property('name', String);
property('date', Date);
set('restPath', pathTo.categories);
});
var Post = describe('Post', function() {
property('title', String);
property('content', String);
property('published', Boolean);
property('date', Date);
set('restPath', pathTo.posts);
});
Category.hasMany(Post, {as: 'posts', foreignKey: 'categoryId'});
내 모델 :
module.exports = function (compound, Category) {
// define Category here
};
내 컨트롤러 :
action('new', function() {
this.title = 'New category';
this.category = new Category;
render();
});
action(function create() {
Category.create(req.body.Category, function (err, category) {
respondTo(function (format) {
format.json(function() {
if (err) {
send({code: 500, error: category && category.errors || err});
} else {
send({code: 200, data: category.toObject()});
}
});
format.html(function() {
if (err) {
flash('error', 'Category can not be created');
render('new', {
category: category,
title: 'New category'
});
} else {
flash('info', 'Category created');
redirect(path_to.categories);
}
});
});
});
});