在autoform hook中访问嵌套数组

时间:2016-01-27 19:28:03

标签: meteor

我有一个看起来像这样的集合:

 "request":{
  type: [Object],
  optional: true,
  autoValue: function() {            
    var input = this.field('requestInput');
    var type = this.field('requestTypeInput');
    var emailTo = this.field('emailToInput');
    var direction = this.field('directionInput');
    var d = new Date;
    //var requestFiles = this.field('requestFiles'); 


    //console.log(requestFiles.value);
    if(!!input.value){
      if(this.isInsert){

         return [{
            "_id":Random.id(),
            date: new Date(),
            type: type.value,
            details: input.value,
            emailTo: emailTo.value,
            direction : direction.value,
           // requestFiles: requestFiles.value,
            createdBy: this.userId
        }];

      } else {

          return {
           $push: {

              "_id":Random.id(),
              date: new Date(),
              type: type.value,
              details: input.value,
              emailTo: emailTo.value,
              direction : direction.value,
             // requestFiles: requestFiles.value,
              createdBy: this.userId
           }
         };
      }

   } else {
     this.unset();
   }
 }
},
'request.$.date': {
type: Date,
optional: true
},
'request.$.details': {
type: String,
optional: true
},
'request.$.createdBy':{
  type: String,
  optional: true
},
"request.$.type":{ 
type: String
},
"request.$._id":{ 
type: String
},
"request.$.emailTo":{
 type: String,
 max: 1000,
 optional: true
  },
"request.$.direction":{
 type: String,
 max: 1000,
 optional: true
},
"request.$.requestFiles":{
 type: [String],
 optional: true
}

我想要做的是使用before hook来设置requestFiles的值但我无法访问它。这就是我到目前为止所做的:

 before:{

     "method-update": function(doc) {
      doc.$set.request.requestFiles = arrayOfFiles.list();
      return doc;
      }
}
这告诉我:

 Uncaught TypeError: Cannot set property 'requestFiles' of undefined.

我也尝试过:

doc.$set.request.0.requestFiles = arrayOfFiles.list();
doc.$set.request[0].requestFiles = arrayOfFiles.list();

我只想传递该数组值。如果有另一种传递该值的解决方案,我将接受它。

0 个答案:

没有答案