Ember.js句柄if,else语句(Ember.js handlebars if, else statement)
我希望有人能够解释我在这里做错了什么。 我使用Ember.js与句柄模板,我已经尝试了很多方式来获得句柄#如果别人为我工作,但它总是返回两个内容的if和else ..这是我目前使用的代码。
App.js:
App = Ember.Application.create({ selectedView: "Home", IsHome: function() { this.get('selectedView') === 'Home' }.property('selectedView') });
index.html头部包含:
<script type="text/x-handlebars" data-template-name="home-view"> Hello, This is the home view. </script> <script type="text/x-handlebars" data-template-name="edit-account"> Hello, This is the account edit view. </script>
并在体内:
<script type="text/x-handlebars"> {{#if App.IsHome}} {{view HomeView}} {{else}} {{view editAccountView}} {{/if}} </script>
这最终显示了页面正文中的两个视图。 任何建议表示赞赏,
谢谢史蒂夫
I'm hoping someone can explain what I'm doing wrong here. I'm using Ember.js with handlebars templates, I've tried a number of ways to get handlebars #if else working for me but it always returns both the contents of if and else.. Here's the code I'm currently using.
App.js:
App = Ember.Application.create({ selectedView: "Home", IsHome: function() { this.get('selectedView') === 'Home' }.property('selectedView') });
index.html head contains:
<script type="text/x-handlebars" data-template-name="home-view"> Hello, This is the home view. </script> <script type="text/x-handlebars" data-template-name="edit-account"> Hello, This is the account edit view. </script>
and in the body:
<script type="text/x-handlebars"> {{#if App.IsHome}} {{view HomeView}} {{else}} {{view editAccountView}} {{/if}} </script>
This ends up showing both views in the body of the page. Any advice is appreciated,
thanks Steve
原文:https://stackoverflow.com/questions/11385326
最满意答案
选项1:
scale_fill_gradientn
ggplot() + geom_tile(data = idw.output, alpha = 0.8, aes(x = longitud, y = latitud, fill = RGlobal)) + scale_fill_gradientn(colours = paleta) + coord_map(xlim = c(-1.7, -1), ylim = c(37.7,38)) + ggtitle("Previsión UVI") + xlab(" ") + ylab(" ")
选项2:
scale_fill_manual
首先转换为一个因素:
idw.output$RGlobal_f <- cut(idw.output$RGlobal, breaks = length(paleta)) ggplot() + geom_tile(data = idw.output, alpha = 0.8, aes(x = longitud, y = latitud, fill = RGlobal_f)) + scale_fill_manual(values = paleta) + coord_map(xlim = c(-1.7, -1),ylim = c(37.7,38)) + ggtitle("Previsión UVI") + xlab(" ") + ylab(" ")
查看如何提供其他标签。
我绝对更喜欢选项1!
Option 1:
scale_fill_gradientn
ggplot() + geom_tile(data = idw.output, alpha = 0.8, aes(x = longitud, y = latitud, fill = RGlobal)) + scale_fill_gradientn(colours = paleta) + coord_map(xlim = c(-1.7, -1), ylim = c(37.7,38)) + ggtitle("Previsión UVI") + xlab(" ") + ylab(" ")
Option 2:
scale_fill_manual
Convert to a factor first:
idw.output$RGlobal_f <- cut(idw.output$RGlobal, breaks = length(paleta)) ggplot() + geom_tile(data = idw.output, alpha = 0.8, aes(x = longitud, y = latitud, fill = RGlobal_f)) + scale_fill_manual(values = paleta) + coord_map(xlim = c(-1.7, -1),ylim = c(37.7,38)) + ggtitle("Previsión UVI") + xlab(" ") + ylab(" ")
See
?cut
on how to provide other labels.I definitely prefer option 1!
相关问答
更多-
调色板与ggplot(Colour palette with ggplot)[2022-08-10]
是的。 scale_fill_gradient是连续的。 scale_fill_manual是离散的,并且明确地measure是数字(而不是因子),所以你看到的是完全预期的行为。 这里有一个玩具的例子来帮助解释: library(rgdal) library(curl) library(ggplot2) library(ggthemes) # get a simple shapefile map_url <- "https://andrew.cartodb.com/api/v2/sql?filename ... -
选项1: scale_fill_gradientn ggplot() + geom_tile(data = idw.output, alpha = 0.8, aes(x = longitud, y = latitud, fill = RGlobal)) + scale_fill_gradientn(colours = paleta) + coord_map(xlim = c(-1.7, -1), ylim = c(37.7,38)) + ggtitle("Previsión UVI") + ...
-
您可以通过为所需字符指定Unicode值来创建自己的形状调色板。 你可以在这里找到各种几何形状的Unicode值。 例如: library(ggplot2) ggplot(mtcars[mtcars$carb %in% 1:4,], aes(wt, mpg, shape=factor(carb), colour=factor(carb))) + geom_point(size=5) + scale_shape_manual(values=c("\u25BA","\u25C4","\ ...
-
我认为geom_tile()会更好 - 使用y和fill sales 。 使用geom_tile()您将获得每个销售值的单独geom_tile()贴,并且能够看到渐变。 ggplot(mydf) + geom_tile(aes(x = 1, y=sales, fill = sales)) + scale_x_continuous(limits=c(0,2),breaks=1)+ scale_fill_gradient2(low = 'blue', mid = 'white', high = 'r ...
-
如何在单个ggplot2图中指定不同的调色板和线条大小(How to specify different palettes and line size within a single ggplot2 plot)[2021-12-29]
您可以在单独的geom_line调用数据的子集: ggplot() + geom_line(data=dataM[dataM$variable!="R",], aes(x=bins, y=value, colour=variable), size = .5, alpha = .9) + geom_line(data=dataM[dataM$variable=="R",], aes(x=bins, y=value, colour=variable), size = 1.5, alpha = .9) + ... -
增加Rg中ggplot2 scale_colour_gradient的对比度?(increasing contrast of ggplot2 scale_colour_gradient in R?)[2023-04-19]
它似乎是黑色到红色或红色到黑色,因此可以使用很少的色彩空间。 您可以使用十六进制代码为低和高设置指定更多特定颜色,并添加黑色背景以提高对比度。 例如: + scale_colour_gradient2(low="#22FF00", mid="white", high="#FF0000", midpoint=median(iris$Sepal.Length)) + theme(panel.grid=element_blank(), panel.background=element_rect(fill="bla ... -
这应该会让你获得最大的成功。 (请注意,如果要绘制颜色对应单元格的实际值(而不是重新缩放),则需要设置scale="none" )。 ncol <- 100 ## Make a vector with n colors cols <- RColorBrewer:::brewer.pal(11,"PuOr") # OR c("purple","white","orange") rampcols <- colorRampPalette(colors = cols, space="Lab")(ncol) ...
-
使用ggplot2每列热图(Heat map per column with ggplot2)[2023-06-07]
要将value作为文本标签添加到每个单元格,可以使用geom_text : p <- ggplot(tableau.m, aes(variable, Net)) + geom_tile(aes(fill = rescale), colour = "white") + scale_fill_gradient(low = "white", high = "steelblue") + geom_text(aes(label=value)) # Add the theme ... -
将scale_colour_gradient转换为R中ggplot2中的log2空间(transforming scale_colour_gradient to log2 space in ggplot2 in R)[2021-12-20]
您也可以使用scale_colour_gradient()内部的scale_colour_gradient() ,方法与scale_y_continuous() 。 df<-data.frame(x=1:100,y=1:100) library(scales) ggplot(df)+geom_line(aes(x=x, y=y, colour=y)) + scale_y_continuous(trans=log2_trans()) + scale_colour_gradient(trans=lo ...