如何访问嵌套的SASS变量?

时间:2016-12-12 18:45:40

标签: ionic-framework sass ionic2

此.scss文件中的几种颜色定义如下:

$colors: (
  primary :   #cd0e11,
  secondary:  #23aa0b,
  danger:     #f53d3d,
  light:      #f4f4f4,
  dark:       #222
);

我如何访问它们?假设我想将某些内容设置为主要内容。

我试过了:

h1 {
color: $colors:primary
}

这是Ionic 2,所以它可能是一个框架特定的东西。

3 个答案:

答案 0 :(得分:7)

我发现这叫做SASS映射。以下将有效。它的工作方式类似于键值提取器。

visit

检查this以获取更多信息。

答案 1 :(得分:1)

你可以试试这个:

package org.robferguson.resteasy.examples.fatjar;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher;

public class Main {

  static final String APPLICATION_PATH = "/api";
  static final String API_PATH_SPEC = "/api/*";
  static final String SWAGGER_UI_PATH_SPEC = "/*";

  public Main() {}

  public static void main( String[] args ) throws Exception
  {
    try
    {
      new Main().run();
    }
    catch (Throwable t)
    {
      t.printStackTrace();
    }
  }

  public void run() throws Exception
  {
    final int port = 8080;
    final Server server = new Server(port);

    // setup Application context
    ServletContextHandler context = new ServletContextHandler();

    // setup JAX-RS (RESTEasy) resources
    ServletHolder apiServlet = new ServletHolder(
        new HttpServletDispatcher());
    apiServlet.setInitOrder(1);
    apiServlet.setInitParameter("resteasy.servlet.mapping.prefix",
        APPLICATION_PATH);
    apiServlet.setInitParameter("javax.ws.rs.Application",
        "org.robferguson.resteasy.examples.fatjar.FatJarApplication");

    // setup static (Swagger UI) resources
    String resourceBasePath = Main.class.getResource(
      "/swagger-ui").toExternalForm();
    context.setResourceBase(resourceBasePath);
    context.setWelcomeFiles(new String[] { "index.html" });

    ServletHolder swaggerUiServlet = new ServletHolder(
      new DefaultServlet());
    swaggerUiServlet.setInitOrder(2);

    context.addServlet(apiServlet, API_PATH_SPEC);
    context.addServlet(swaggerUiServlet, SWAGGER_UI_PATH_SPEC);

    server.setHandler(context);
    server.start();
    server.join();
  } 
}

答案 2 :(得分:0)

创建地图后,使用map-get()函数。如有必要,您还可以遍历每个:https://webdesign.tutsplus.com/tutorials/an-introduction-to-sass-maps-usage-and-examples--cms-22184

$map: (
 color01: value,
 color02: nextValue,
 color03: thirdValue
); 

.element {
  content: map-get($map, color01);
}