我有一个基本的select元素,其中的选项连接到一小组数据,这些数据正在使用下拉列表进行过滤。最初在页面加载时,select元素的值为undefined
(根据控制台),但是在选择任何选项后,它将采用该选项的值。
如何返回undefined
?基本上我希望能够在列表中选择一个可以返回显示所有数据的选项。以下是我在JSBin上的应用程序:
答案 0 :(得分:1)
我很困惑,您使用的是lapply(COL.NAMES, function(x){
temp=df[!(is.na(df$paste(x))),]
rows=length(temp$ID)
num_comp=length(unique(temp$ID))
return(rows)
return(num_comp)
remove(temp)
})
,但您还提供了静态选项。
要在这种情况下进行快速修复,您可以删除该ng选项并取消注释COL.NAMES<-c("Var1","Var2","Var3","Var4","Var5","Var6","Var7","Var8","Var9","Var10","Var11","Var12","Var13","Var14","Var15")
structure(list(ID = structure(c(1L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 2L, 3L, 4L, 1L, 5L, 6L, 7L, 8L, 9L, 10L, 11L), .Label = c("Comp1",
"Comp10", "Comp11", "Comp12", "Comp2", "Comp3", "Comp4", "Comp5",
"Comp6", "Comp7", "Comp8", "Comp9"), class = "factor"), Date = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L), .Label = c("0/1/2014", "0/1/2015"), class = "factor"),
Var1 = c(0.57, 0.34, 0.38, 0.93, 0.54, 0.17, 0.08, 0.28,
0.99, 1, 0.61, 0.73, 0.15, 0.09, 0.64, 0.3, 0.12, 0.79, 0.79,
0.15), Var2 = c(0.7, 0.77, 0.93, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.46, 0.26), Var3 = c(0.65,
0.7, 0.83, 0.7, 0.43, 0.81, 0.21, 0.44, 0.25, 0.77, 0.24,
0.29, 0.87, 0.42, 1, NA, NA, NA, NA, 0.79), Var4 = c(1, 0.7,
0.69, NA, NA, NA, NA, 0.2, 0.61, 0.89, 0.45, 0.02, 0.97,
0.33, 0.34, 0.81, 0.99, 0.35, 0.48, 0.33), Var5 = c(0.47,
0.95, 0.38, 0.69, 0.84, 0.21, 0.62, 0.59, 0.45, 0.63, 0.18,
0.49, NA, NA, NA, NA, 0.17, 0.15, 0.6, 0.44), Var6 = c(NA,
NA, NA, NA, 0.24, 0.07, 0.75, 0.24, 0.82, 0.14, 0.86, 0.63,
0.82, 0.92, 0.55, 0.22, 0.87, 0.69, 0.64, 0.73), Var7 = c(0.2,
0.11, 0.82, 0.31, 0.97, NA, NA, NA, NA, 0.83, 0.84, 0.81,
0.72, 0.36, 0.09, 0.15, 0.46, 0.79, 0.75, 0.39), Var8 = c(0.28,
0.55, NA, NA, NA, NA, 0.56, 0.89, 0.92, 0.46, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA), Var9 = c(0.11, 0.36, 1, 0.44,
0.53, 0.6, 0.24, 0.56, 0.6, 0.55, 0.55, 0.05, 0.77, 0.9,
NA, NA, NA, NA, 0.4, 0.33), Var10 = c(0.74, 0.13, 0.09, 0.61,
NA, NA, NA, NA, 0.27, 0.71, 0.56, 0.3, 0.36, 0.44, 0.78,
0.9, 0.46, 0.49, 0.87, 0.36), Var11 = c(0.58, 0.99, 0.07,
0.83, 0.45, 0.07, 0.16, 0.43, 0.34, 0.31, 0.06, 0.67, 0.02,
0.52, 0.19, 0.49, 0.31, 0.02, 0.62, 0.21), Var12 = c(0.93,
0.26, 0.77, 0.8, 0.67, 0.83, 0.12, 0.39, 0.78, 0.75, 0.44,
NA, NA, NA, NA, 0.42, 0.49, 0.06, 0.8, 0.54), Var13 = c(0.44,
0.75, NA, NA, NA, NA, 0.58, 0.3, 0.47, 0.88, 0.36, 0.21,
0.87, 0.33, 0.12, 0.31, 0.95, 0.59, 0.18, 0.43), Var14 = c(0.55,
0.03, 0.37, 0.66, NA, 0.91, 0.78, 0.84, 0.96, 0.34, 0.25,
0.92, 0.71, 0.41, 0.23, 0.54, 0.8, 0.87, 0.3, 0.37), Var15 = c(0.71,
0.66, 0.01, 0.7, 0.4, 0.04, 0.3, 1, 0.59, 0.69, 0.88, 0.28,
0.44, 0.51, 0.2, 0.17, 0.6, 0.11, 0.85, 0.04)), .Names = c("ID",
"Date", "Var1", "Var2", "Var3", "Var4", "Var5", "Var6", "Var7",
"Var8", "Var9", "Var10", "Var11", "Var12", "Var13", "Var14",
"Var15"), class = "data.frame", row.names = c(NA, -20L))
并删除它的值。
像:
ng-options
答案 1 :(得分:1)
添加自定义过滤功能
$scope.filterByGenre = function(item){
if (!$scope.selectedGenre || $scope.selectedGenre == 'All'){
return true;
}
return item.genre && item.genre.indexOf($scope.selectedGenre) != -1;
}
将您的<select>
更改为:
<select ng-model="selectedGenre"
ng-options="choice as choice for (idx, choice) in genres"
name="genre"
class="genre-dropdown">
</select>
将<tr ng-repeat="...
过滤器更改为:
<tr ng-repeat="movie in movies | filter:searchBar | filter:filterByGenre | orderBy:sortType:sortReverse">
答案 2 :(得分:1)
你可以这样做:
$scope.selectedGenre = "";//set the model to blank.
$scope.genres = 'All,Action,Adventure,Animation,Biography,Comedy,Crime,Drama,Fantasy,History,Horror,Romance,Sci-Fi,Western';
//create an array after splitting the commas
$scope.genresAry = $scope.genres.split(',');
$scope.genresAry.push("");//push blank into the array.
在HTML中使用genresAry
。
<select ng-model="selectedGenre"
ng-options="choice as choice for (idx, choice) in genresAry"
ng-change="handleSelect()"
name="genre"
class="genre-dropdown">
工作代码here