기사를 표시하려고하는데 그 기사 아래에 기사에 속하는 문헌 데이터를 표시하고 싶습니다. 컬렉션 문헌에는 많은 문서가 있지만,article_id: article._id
나는 복잡하다고 생각하지만 이것이 내가하려는 것입니다.
publication.js
Meteor.publish('references', function(){
return Articles.find({});
});
Router.js
Router.route('/cars', {
name: 'main',
data: function() {
return {
article: Articles.find({})
}
}
});
template_1.html
<template name="main">
<div>
{{article._id}}
<header><h1>{{article.title}}</h1></header>
{{article.content}}
{{>literature reference=article._id}}
</div>
</template>
template_2.html
<template name="literature">
Same id: {{this.reference}}
Now get all item of literature-collection
<ul>
{{#each items}}
<li>{{this.title}}</li>
{{/each}}
</ul>
</template>
helper.js
Template.literature.helpers({
items: function() {
return Literature.find({article_id: article._id}); /* this should be the id the first template */
}
});
더 쉬울 수 있다고 생각합니다. 그래서 두 번째 생각은 문헌 쿼리를 라우터에 넣는 것입니다.
Router.route('/cars', {
name: 'main',
data: function() {
return {
article: Articles.find({}),
items: Literature.find({article_id: article._id}) /* How do I get the variable which is needed? */
}
}
});
당신은 사용해야합니다 meteor add reywood:publish-composite
따라서 게시 기능은 다음과 같습니다.
Meteor.publishComposite('articles', function(){
return {
find: function(){
return Articles.find();
},
children: [{
find: function(article){
return Literature.find({article_id: article._id})
}
}]
}
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다