2013-03-13 1 views
2

부트 스트랩 모달 대화 상자 안의 콜렉션에서 값을 가져 오려고 할 때이 문제가 있습니다. 부트 스트랩 모달 대화 상자에서 Meteor 템플릿 렌더링

는 클라이언트 측 자바 스크립트 코드입니다 :

Template.Modal_edit_client.edit_client_name = function() { 
    var c = Clients.findOne({_id: Session.get("current_editing")}); 
    return c.name; 
}; 

이 템플릿입니다 :

<template name="Modal_edit_client"> 
    <div id="Modal_edit_client" class="modal hide fade"> 
     <div class="modal-header"> 
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> 
      <h3>Editar cliente</h3> 
     </div> 
     <div class="modal-body"> 
      <form id="edit_client" action=""> 
       <fieldset> 
        <input id="edit_client_name" placeholder="Nombre y apellido" type="text" value="{{edit_client_name}}"> 
        {{edit_client_name}} 
       </fieldset> 
      </form> 
     </div> 
     <div class="modal-footer"> 
      <a id="edit_client_cancel" href="#" class="btn">Cancelar</a> 
      <a id="edit_client_save" href="#" class="btn btn-primary">Guardar</a> 
     </div> 
    </div> 
</template> 

페이지 렌더링하지 않았고 이는 conosole을 보여주는 것입니다 :

Uncaught TypeError: Cannot read property 'name' of undefined 
Exception from Meteor.flush: TypeError: Cannot call method 'firstNode' of undefined 
    at Object.Spark.renderToRange (http://localhost:3000/packages/spark/spark.js?ba288278f8e36e3529187cea4590001f50ef0f95:545:25) 
    at http://localhost:3000/packages/spark/spark.js?ba288278f8e36e3529187cea4590001f50ef0f95:860:13 
    at http://localhost:3000/packages/deps/deps-utils.js?0c00e493224f891c3d6c82a23693ba55e0f47611:78:31 
    at _.extend.run (http://localhost:3000/packages/deps/deps.js?d804638a4633c2f6488827923ba5fbd00f07d518:19:20) 
    at rerun (http://localhost:3000/packages/deps/deps-utils.js?0c00e493224f891c3d6c82a23693ba55e0f47611:78:11) 
    at http://localhost:3000/packages/deps/deps.js?d804638a4633c2f6488827923ba5fbd00f07d518:71:15 
    at Array.forEach (native) 
    at Function._.each._.forEach (http://localhost:3000/packages/underscore/underscore.js?017a0dea6ebb07eec57a1541a0fd524665e769bd:79:11) 
    at http://localhost:3000/packages/deps/deps.js?d804638a4633c2f6488827923ba5fbd00f07d518:69:13 
    at Array.forEach (native) logging.js:30 
Exception from Meteor.flush: TypeError: Cannot call method 'firstNode' of undefined 
    at Object.Spark.renderToRange (http://localhost:3000/packages/spark/spark.js?ba288278f8e36e3529187cea4590001f50ef0f95:545:25) 
    at http://localhost:3000/packages/spark/spark.js?ba288278f8e36e3529187cea4590001f50ef0f95:860:13 
    at http://localhost:3000/packages/deps/deps-utils.js?0c00e493224f891c3d6c82a23693ba55e0f47611:78:31 
    at _.extend.run (http://localhost:3000/packages/deps/deps.js?d804638a4633c2f6488827923ba5fbd00f07d518:19:20) 
    at rerun (http://localhost:3000/packages/deps/deps-utils.js?0c00e493224f891c3d6c82a23693ba55e0f47611:78:11) 
    at http://localhost:3000/packages/deps/deps.js?d804638a4633c2f6488827923ba5fbd00f07d518:71:15 
    at Array.forEach (native) 
    at Function._.each._.forEach (http://localhost:3000/packages/underscore/underscore.js?017a0dea6ebb07eec57a1541a0fd524665e769bd:79:11) 
    at http://localhost:3000/packages/deps/deps.js?d804638a4633c2f6488827923ba5fbd00f07d518:69:13 
    at Array.forEach (native) logging.js:30 
Exception from Meteor.flush: TypeError: Cannot call method 'firstNode' of undefined 
    at Object.Spark.renderToRange (http://localhost:3000/packages/spark/spark.js?ba288278f8e36e3529187cea4590001f50ef0f95:545:25) 
    at http://localhost:3000/packages/spark/spark.js?ba288278f8e36e3529187cea4590001f50ef0f95:860:13 
    at http://localhost:3000/packages/deps/deps-utils.js?0c00e493224f891c3d6c82a23693ba55e0f47611:78:31 
    at _.extend.run (http://localhost:3000/packages/deps/deps.js?d804638a4633c2f6488827923ba5fbd00f07d518:19:20) 
    at rerun (http://localhost:3000/packages/deps/deps-utils.js?0c00e493224f891c3d6c82a23693ba55e0f47611:78:11) 
    at http://localhost:3000/packages/deps/deps.js?d804638a4633c2f6488827923ba5fbd00f07d518:71:15 
    at Array.forEach (native) 
    at Function._.each._.forEach (http://localhost:3000/packages/underscore/underscore.js?017a0dea6ebb07eec57a1541a0fd524665e769bd:79:11) 
    at http://localhost:3000/packages/deps/deps.js?d804638a4633c2f6488827923ba5fbd00f07d518:69:13 
    at Array.forEach (native) 

문제는 첫 번째 줄에 Uncaught TypeError: Cannot read property 'name' of undefined으로 표시됩니다. 그 후 템플릿을 렌더링 c.name !== undefined amd 때까지 기다릴 수있는 방법이 있습니까?

+0

을 읽으려고 전에 기록 [요지] (http://gist.github.com)이 있음을 확인하면서 사건을 처리해야하는 것은 좋은 옵션 – Prashant

답변

3

유성우가 브라우저에서 처음으로로드 될 때 컬렉션의 서버 데이터는 없지만 템플릿은 계속 렌더링됩니다. 세션이 설정되지 않은 경우와 마찬가지입니다. 그래서 당신은 그것의 로딩 (막 대형 코드에 대해 name

Template.Modal_edit_client.edit_client_name = function() { 
    var c = Clients.findOne({_id: Session.get("current_editing")}); 
    if(c) return c.name; 
}; 
+0

감사합니다! 정말 도움이되었지만 여전히 템플릿에서 렌더링 된 값을 볼 수 없습니다. – rec

+0

"current_editing"에 대한 세션 해시를 설정했으며 컬렉션의 ID와 일치합니까? '클라이언트를 실행하는 경우. – Akshat

+0

네, 정확히 내가 원하는 것은 나에게 문서의 ID를 제공합니다. – rec

관련 문제