繁体   English   中英

将助手属性链接到流星中的div

[英]link helpers properties to a div in Meteor

我实际上正在努力解决一些简单的问题。 我希望我的助手在模板“ fullArticle”上执行。

我试图将模板扭曲到div中,但是在div上使用name HTML属性是不正确的。 因此,我尝试了一个类,但控制台上仍然没有任何内容。

我可以在我的助手上写这样的东西:

'.article': function(){...}

或更好,使用数据HTML属性

'[data-name="article"]': function(){...}

甚至直接定位模板名称(我在以下代码中尝试执行的操作:

fullArticle: function(){...}

fullArticle.html

<template name="fullArticle">
    <div class="article">
    {{_id}}
    <h1>Full article {{title}}</h1>
    <h3><small>{{date}}</small></h3>
    <p>{{content}}</p>
    </div>
</template>

fullArticle.js

if (Meteor.isClient){
  Template.fullArticle.helpers({
    fullArticle: function(){
      console.log("id is : " + this._id);
      //return Articles.findOne({_id: id});
    }
  });
}

routes.js

Router.route(':categoryName/article/:_id', function(){
    this.render('fullArticle', {
        data: function(){
            return {_id: this.params._id};
        }
    });
});

您知道如何使其工作或提出更好的解决方案吗?

在下面,您可以找到typical schematypical schema如何从数据库获取数据并在客户端显示。 请以此为灵感。

在服务器端创建发布功能:

Meteor.publish('article',function(articleId){
  check(articleId, String);
  return Articles.find({_id:articleId})
})

routes.js

Router.route(':categoryName/article/:_id',{
   name:'full.article',
   template: 'fullArticle',
   waitOn: function () {
    return Meteor.subscribe( 'article', this.params._id ),
   },
   data : function(){
     return Articles.findOne( { _id: this.params._id } ) 
   }
})

fullArticle.html

<template name="fullArticle">
    <div class="article">
    {{_id}}
    <h1>Full article {{title}}</h1>
    <h3><small>{{date}}</small></h3>
    <p>{{content}}</p>
    </div>
</template>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM