保存实例时flatiron resourcefuljs回调

时间:2013-03-19 04:55:30

标签: node.js flatiron.js

假设我有:

var resourceful = require("resourceful");

BaseTopic = function () {
    this.string("name");
    this.string("slug");
}

slugify = function (someString) {
    // do some things here
}

Topic = resourceful.define("topic", BaseTopic);

现在,我想要的是每次我保存Topic的新实例时,slug字段都会更新,如下所示:

jsTopic = new Topic({name : "javascript"});

jsTopic.save(function (err, result) {
   // in here slug field is defined
   // so the slug field is saved to the db
   console.log(result);
})

每次我创建一个新实例或保存它时,slug字段会自动填充。这可能吗?

0 个答案:

没有答案