MeteorJS和x可编辑反应式模板

MeteorJS and x-editable-reactive-template

本文关键字:反应式 编辑 MeteorJS      更新时间:2023-09-26

我想在我的MeteorJS项目中使用x-editable-reactive-template。我的模板如下所示:

  <template name="jobSeeker">
    <div class="items-form">
      {{> xEditable type="text" success=onSuccess placement="right" mode="inline emptytext="Your name..." value=usernameValue }}
    </div>
  </template>

我的模板助手如下所示:

    Template.jobSeeker.helpers({
      usernameValue: function()
      {
         Meteor.call('getProfileUsername',function(error, result) {
                if (error) return alert(error.reason);
                return result;    
                });   
      }
 });

服务器端的流星方法:

 Meteor.methods({ 
 getProfileUsername: function() {
   var user = Meteor.user();    
   var currentUsername = Meteor.users.findOne(user._id);
   return currentUsername.username;
}
}); 

用户保存在MongoDB中,在集合中有一个带有字段用户名的文档。但是有些东西不起作用!有什么帮助吗?

您将在方法回调中返回值,该值不会向帮助程序返回值

试试这个

Template.jobSeeker.helpers({
      usernameValue: function()
      {
         Meteor.call('getProfileUsername',function(error, result) {
                if (error) 
                    return alert(error.reason);
                Session.set("username",username);    
                });  
         return  Session.get("username"); 
      }
 });