맞습니다. 데이터가 제대로로드 된 후 클라이언트 측 구독 컬렉션의 내용을 가져 오는 것에 따라 코드가 실행되도록해야합니다.
당신이 새로운 유성 1.0.4에 도입 된 패턴을 사용하여 달성 할 수있는 다음 Spacebars 템플릿 선언에서 https://docs.meteor.com/#/full/Blaze-TemplateInstance-subscribe
client/views/svg/svg.js
Template.outer.onCreated(function(){
// subscribe to the publication responsible for sending the Pushups
// documents down to the client
this.subscribe("pushupsPub");
});
client/views/svg/svg.html
<template name="outer">
{{#if Template.subscriptionsReady}}
{{> svgTemplate}}
{{else}}
Loading...
{{/if}}
</template>
을, 우리는 캡슐화를 사용 outer
템플리트 레벨 등록 패턴을 처리하기위한 템플리트. onCreated
라이프 사이클 이벤트의 발행물을 구독하고 특별 대응 헬퍼 Template.subscriptionsReady
을 사용하여 구독이 준비되면 (브라우저에서 데이터를 사용할 수 있음) svgTemplate
만 렌더링합니다. 또한
Template.svgTemplate.onRendered(function(){
console.log(Pushups.find().fetch());
});
당신이이 iron:router
(https://github.com/iron-meteor/iron-router), 어떤이 제공하는 사용할 수 있습니다, 우리가 반드시 데이터를 클라이언트로의 길을 만들었 기 때문에이 시점에서 , 우리는 안전하게 svgTemplate
onRendered
라이프 사이클 이벤트에 Pushups
수집을 조회 할 수 있습니다 이 일반적인 Meteor 관련 문제를 해결하기위한 또 다른 디자인 패턴으로, 템플릿 레벨 대신 경로 레벨에서 서브 스크립 션 처리를 이동하십시오.
프로젝트에 패키지를 추가
lib/router.js
Router.route("/svg", {
name: "svg",
template: "svgTemplate",
waitOn: function(){
// waitOn makes sure that this publication is ready before rendering your template
return Meteor.subscribe("publication");
},
data: function(){
// this will be used as the current data context in your template
return Pushups.find(/*...*/);
}
});
meteor add iron:router
당신이 원하는 것을 얻을 플러스 추가 기능이 많이 있습니다 코드의 간단한 조각을 사용. Iron Router 가이드에서 이러한 기능에 대해 자세히 설명합니다.
https://github.com/iron-meteor/iron-router/blob/devel/Guide.md
편집 18/3/2015은 : 그것은 오래된 자료를 포함하고 여전히 그럼에도 불구하고 upvotes을 받았기 때문에 답을 재 작업.
폭탄 엉덩이 응답 독 답변을 재 작업을위한 –
감사 : 클라이언트 코드가 데이터를 가져 같은 방법을 사용할 수 있도록이 예에서는, 내 쿼리를 중앙 집중화합니다. 유성은 빠르게 움직이며 시대에 뒤 떨어진 많은 정보가 있습니다. –
Meteor의 최신 릴리스에 반영된 디자인 패턴 인 템플릿 수준 가입을 사용하기 위해 다시 답을 수정했습니다. – saimeunt