私はnode.jsとsailsの初心者ですが、簡単なので気に入っています:) 実際、MongoDB ans Sails-mongoを使用してsails Framework 0.10rc3を使用しています。
ウォーターラインの貢献者は、mongodb ( https://github.com/balderdashy/sails-mongo/issues/44#issuecomment-35561040 ) のようにモデルに埋め込まれたドキュメントの大ファンではないことを知っていますが、とにかく、方法を知りたかった「this」変数はそれらで機能し、内部配列の現在の要素を取得する方法。
モデルの例を次に示します (これを ProjetSpan と呼ぶことができます)。
module.exports = {
attributes: {
proj:
{
model:'Projet'
},
spans:
{
start:
{
type: 'DATETIME',
required: true,
datetime: true,
before: function() {
if (this.end < this.proj.end)
return this.end;
else
return this.proj.end;
}
},
end:
{
type: 'DATETIME',
required: true,
datetime: true,
after: function() {
if (this.start > this.proj.start)
return this.start;
else
return this.proj.start;
}
}
}
}
};
この場合、「これ」はどのように機能しますか? 「これ」はスパンですか (したがって、this.end は機能し、this.proj.end は機能しません)、「これ」は ProjetSpan ですか (ans したがって、this.proj.end は機能しますが、this.end は機能しません) ?
最後に、この埋め込みコンテキストで this.end (現在のスパンの変数) と this.proj.end (現在のドキュメントの関連付けの変数) を機能させる方法は?