Node.js 使用component.js更新控制器中的属性

Node.js 使用component.js更新控制器中的属性,node.js,compoundjs,Node.js,Compoundjs,我尝试使用composite.js创建博客。我有两个表,“Category”和“Post”,在每个表中我都有date属性,但是当我生成表时,我得到了一个表单,在每个“new”视图中都有date属性的输入 我想在创建控制器时自动更新控制器中的日期属性 我该怎么做 我的谢玛: var Category = describe('Category', function () { property('name', String); property('date', Date); s

我尝试使用composite.js创建博客。我有两个表,“Category”和“Post”,在每个表中我都有date属性,但是当我生成表时,我得到了一个表单,在每个“new”视图中都有date属性的输入

我想在创建控制器时自动更新控制器中的日期属性

我该怎么做

我的谢玛:

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);
                }
            });
        });
    });
});

如果希望在默认情况下设置日期,可以在模式中这样做:

var Category = describe('Category', function () {
    property('name', String);
    property('date', Date, {default: new Date});
    set('restPath', pathTo.categories);
});
如果不希望用户看到日期字段,可以将其从视图标记中删除,因为数据对象已预填充