简体   繁体   English

将类添加到由大气层包创建的模板内的DOM元素中?

[英]Adding a class to a DOM element inside a template created by an atmosphere package?

I am currently utilizing Meteor, the materializecss atmosphere package, and the user-accounts:materialize atmosphere package. 我目前正在使用Meteor,materializecss气氛包和用户帐户:materialize气氛包。 I am attempting to use materialize class-based styling to change the style of the user-accounts:materialize sign-in page, which is created by the {{>atForm}} template. 我正在尝试使用基于实现的基于类的样式来更改由{{> atForm}}模板创建的user-accounts:materialize登录页面的样式。

Template.atForm.onRendered( function(){
  var element = $(".at-form, .at-btn");
  element.addClass("grey lighten-2 grey-text text-darken-4");
});

This works great when the page is initially rendered. 最初呈现页面时,这非常有用。 However, if I sign-in, then sign-out, the sign-in template is again presented but this time the onRendered() function isn't called and my styling is lost. 但是,如果我先登录然后注销,则会再次显示登录模板,但是这次没有调用onRendered()函数,并且样式丢失了。 How do I avoid that? 我该如何避免呢?

And is there a better way to influence elements inside a 3rd party template than calling onRendered()? 有没有比调用onRendered()更好的方法来影响第三方模板中的元素?

I would recommend using https://github.com/aldeed/meteor-template-extension to override the package template with your own. 我建议您使用https://github.com/aldeed/meteor-template-extension覆盖您自己的软件包模板。 Much easier approach, I think. 我认为,这种方法要容易得多。

@Kyll - I assummed that the README was enough of an example; @Kyll-我认为自述文件足以说明一个例子; here is how you could use it: 这是您如何使用它:

add the package to the meteor project with: 使用以下命令将包添加到流星项目中:

meteor add aldeed:template-extension

Add your new template 添加新模板

<template name="myTemplate">...</template>

In the startup code on the client side, override the template: 在客户端的启动代码中,覆盖模板:

Template.myTemplate.replaces("originalTemplateName");

The problem is that at-form has sub templates that change. 问题在于表单上的子模板会发生变化。 You need to handle onRendered for each of them to make sure your class is applied to them all. 您需要为它们每个处理onRendered,以确保将您的类应用于所有它们。

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

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