단일 문서에 대한 구조가 아래와 같은 사용자 테이블이 있습니다.
{
"profile" : {
"name" : "new user",
"gender" : ""
},
"followers" : [
{
"id" : "yQLrjsbAnKHW7Zoef",
"name" : "vid vid"
},
{
"id" : "bGLrjsbAnKHW7Zoef",
"name" : "sid sid"
}
]
}
내 도우미 기능은
Template.followers.helpers({
followers: function () {
return Meteor.users.find({_id: Meteor.userId()},{_id:0,followers:1, profile:1});
}
});
이제 팔로워의 데이터를 다음과 같이 표시하고 싶습니다.
name: Vid
name: Sid
기본적으로 템플릿의 추종자 배열에있는 요소에 액세스하고 싶습니다. 현재 그것은
{{#each followers}}
{{ profile.name}}
{{ followers}}
{{/each}}
고쳤다.
문제는 Meteor.users.find()
제한된 필드 만 반환 한다는 것 입니다. 먼저 users
게시 된 메서드에서 필드 지정자를 사용해 보았지만 작동하지 않았습니다. 그래서 다음은 내가 한 일입니다.
서버 측에서 새 변수를 다음과 같이 선언했습니다.
UserProfiles : = Meteor.users;
필요한 필드를 지정하는 새 게시 방법 추가 : 여기에 코드 입력
Meteor.publish('UserProfiles', function () {
return UserProfiles.find({},{
fields : {
'followers' : 1,
'profile' : 1,
'createdAt' : 1
}
});
});
클라이언트 측에 다음 줄을 추가했습니다.
UserProfiles : = Meteor.users;
Meteor.subscribe("UserProfiles");
그런 다음 내 파일에서 쿼리를 실행하고 다음과 같이 반환했습니다.
users: function (){
return UserProfiles.find(selector, {
fields : {
'followers' : 1,
'profile' : 1,
'createdAt' : 1
}
});
}
내부 템플릿 코드 :
{{#each users}}
Follower of {{profile.name}}
{{#each followers}}
{{> follower}}
{{/each}}
{{/each}}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다