저는 node.js와 돛에 새로운 것 같습니다. 그렇기 때문에 쉽게 마음에 듭니다. :) 실제로 돛과 함께 Framework 0.10rc3과 MongoDB와 sails-mongo를 함께 사용하고 있습니다.임베디드 문서의 모델에 대한 'this'변수는 어떻게됩니까?
mongodb (https://github.com/balderdashy/sails-mongo/issues/44#issuecomment-35561040) 모델에서 워터 라인의 참여자가 모델에 포함 된 문서의 큰 팬이 아니라는 것을 알고 있지만 어쨌든이 'this'변수가 어떻게 작동하는지, 그리고 현재 요소를 검색하는 방법을 알고 싶었습니다. 내부 배열.
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;
}
}
}
}
};
이 어떻게 '이'이 경우에 작동합니다 : 여기
모델의 exemple (우리가 ProjetSpan를 호출 할 수있는)를인가? 'this'는 span이기 때문에 this.end는 작동하지 않고 this.proj.end가 아니거나 ProjetSpan (this.proj.end가 작동하지만 this.end는 작동하지 않습니다)입니까?마지막으로 this.end (현재 범위의 변수) 및 this.proj.end (현재 문서의 연결의 변수)를이 포함 된 컨텍스트에서 사용하는 방법은 무엇입니까?
고맙습니다. 객체 검사의 경우 this.proj! = null && typeof this.proj === 'object''를 작성했지만'span '은 무엇입니까? 이 상태에서 객체, 배열 또는 다른 것이 있습니까? – DestyNova
"spans"는 사용자가 설정 한 JSON 유형이됩니다. 객체 또는 배열 일 가능성이 큽니다. 안타깝게도 그것들은 모두'typeof' "object"이지만,'sails.util.isArray()'를 사용하여 배열을 테스트 할 수 있습니다 ('sails.util'은 Lodash를 래핑합니다). – sgress454
쿨 thx :)! 권장 사항을 따르기 위해 모델을 변경했지만 어떤 시점에서는 딥 연관성 테스트가 어떻게됩니까? if (this.projCollab! = null && typeof this.projCollab === 'object') && (this.projCollab.proj! = null && typeof this.projCollab.proj === 'object')) {if (this.end
DestyNova