1
에 전달할 때 정의되지 않은 오류의 속성을 읽을 수 없으므로 계속 오류가 발생합니다 : Exception in template helper: TypeError: Cannot read property '_id' of undefined at Object.editable
. 나는 그것을 운이 좋으면 디버깅하려고 노력했다.사용자 데이터를 유성 템플릿
user object
을 editUser template
에 전달하려고합니다. 따라서 편집을 클릭하고 양식을 가져올 때 입력란에 user previous values
이 표시 될 수 있지만 양식에 값이 표시되지 않습니다. 여기
id
과
user object
를 전달하는 시도
# users.js
// Helpers
Template.user.helpers({
user:() => {
let user = Meteor.user() ? Meteor.user() : 'Unable to pull user info';
return user
},
editable: function() {
let currentUserId = Meteor.user()._id;
let currentUser = Meteor.user();
// let currentUserFind = Meteor.users.findOne({_id: this._id});
return Session.equals('editUser', currentUserId);
}
});
# user.tpl.jade
// Events
Template.user.events({
'click .form-edit'(e) {
e.preventDefault();
let currentUser= Meteor.user({});
let currentUserId = Meteor.user()._id;
let currentUserFind = Meteor.users.findOne({_id: this._id});
console.log(currentUserId);
console.log(currentUserFind);
// console.log(this._id);
Session.set('editUser', currentUserId);
// Session.set('editUser', this._id);
}
});
if editable
+editUser
else
with currentUser
.card.card--user
h3.card__title= username
p.card__content= profile.email
p.card__content= profile.firstName
p.card__content= profile.lastName
p.card__content= profile.bio
button.card__btn.form-edit Edit
하지만 오류가 사라 얻을 수 없습니다. 어떤 도움을 주시면 감사하겠습니다.
감사합니다. 'Meteor.userId()'는 실제로 내 오류 문제를 해결했습니다. 그래도 내 편집 필드에서 사용자 데이터를 볼 수 없습니다. 어떻게 해결할 수 있니? 감사합니다. – intercoder
코드의 마지막 부분을 이해할 수 없지만 현재 사용자와 세션 도우미가 있으므로 템플릿에서 사용할 수 있습니다. 예를 들어 입력 필드를 사용자 이름으로 미리 채우려면 . 그건 그렇고, 유성은 이미 도우미 currentUser를 제공합니다, 당신은 그것을 정의 할 필요가 없습니다. – Kostas
안녕하세요. 'value ='{{currentUser.profile.name}} ''입력란에 문제가 해결되었습니다. 나는 그것을'value = '{{user.profile.name}}''으로 전달하려했지만 아무 것도 볼 수 없었습니다. 왜 그런지 아십니까? 추신 : 코드의 마지막 부분은 단지 옥의 구문이며, 스페이스 바 및 불꽃의 {{username}}과 동일합니다. – intercoder