2014-05-17 3 views
1

나는 "capacitaciones"라고하는 콜렉션을 가지고 있는데, 그 중 하나는 "comentarios"라는 배열입니다. 내가 푸시 할 때 문제가 있습니다. 코드에서 [Object object]를 반환합니다. 내 모델과 다음 내 컨트롤러 :배열을 누르면 Object 객체가 반환됩니다.

모델

module.exports = { 
    attributes: { 
    title:{ 
     type:'STRING', 
     required:true 
    }, 
    urlmp4:{ 
     type:'STRING', 
     url:true, 
     required:true 
    }, 
    urlogv:{ 
     type:'STRING', 
     url:true, 
     required:true 
    }, 
    likes:{ 
     type:'integer' 
    }, 
    unlikes:{ 
     type:'integer' 
    }, 
    comentarios:{ 
     type:'array' 
    } 
    } 
}; 

컨트롤러

comment: function(req,res,next){ 
    Capacitaciones.findOne({id: req.param('id')}).exec(function (err,capacitacion){ 
     if (err) return next(err); 
     if(capacitacion){ 
      capacitacion.comentarios.push({"usuario":req.session.username,"comentario":req.param('comentario')}); 
      console.log(capacitacion.comentarios); 
      capacitacion.save(function (err){ 
       if (err){ 

        return next(err); 
       } 
       res.view('capacitaciones/show', {capacitaciones: capacitacion}); 
      }); 
     } 
     else{ 
      return next(); 
     } 
    }); 
} 
,536,

두 개의 값 "Usuario"와 "Comentario"를 푸시하고 싶다면, "connsole.log (capacitacion.comentarios); "그것은 내가 밀어하고 값하지만 내보기 반환 정말 당신의 도움을 주셔서 감사합니다 것

<div class="row-fluid text-center"> 
    <div class="col-md-10 col-md-offset-1"> 
     <legend class="text-success text-left"><strong>Comentarios</strong></legend> 
     <form action="/Capacitaciones/comment/<%= capacitaciones.id %>" method="POST" class="form-horizontal" role="form"> 
      <textarea class="form-control" name="comentario" rows="3" maxlength="200"></textarea> 
      <br> 
      <button type="submit" class="btn btn-primary pull-right" id="btn"> 
       <strong>Comentar</strong> 
      </button> 
     </form><br> 
    </div> 
</div> 

<div class="row-fluid text-center"> 
    <div class="col-md-10 col-md-offset-1"> 
    <br> 
     <table class="table table-condensed table-bordered"> 

      <% _.each(capacitaciones.comentarios, function(comentarios){ %> 
       <tr class="success"> 
        <td><h4 class="text-primary text-left"><strong><%= comentarios.usuario %></strong></h4></td> 
       </tr> 
       <tr> 
        <td><p class="text-left"><%= comentarios.comentario %></p></td> 
       </tr> 
      <% }) %> 

     </table>   
    </div> 
</div> 

[개체 개체]

보기, 감사를 반환하고 축복.

+2

보기에 대한 코드를 포함하도록 질문을 편집 할 수 있습니까? – JohnnyHK

+0

보기가 추가되었습니다. – MelgoV

+0

어떤 버전의 Sails를 사용하고 있습니까? 어떤 데이터베이스 어댑터? – sgress454

답변

0

문제가 해결! 내 문제 내 url 규칙, 정확한 URL을 보내지 않았다.

관련 문제