我正在AngularJS中实现一个搜索功能,我希望有一条消息"没有找到结果"什么时候没有比赛。由于我只过滤了一些字段而不是所有字段,我编写了一个单独的过滤函数,应用于ng-if
以检查条目是否与搜索匹配。现在我需要在ng-repeat
完成后计算生成的面板,所以我尝试使用指令after-repeat
,并从results
内部SearchController
为<div ng-if="searchctrl.results<1">No matches.</div>
<uib-accordion close-others="true">
<uib-accordion-group ng-if="searchfilter(lokal)" is-open="isopen" ng-repeat="lokal in lokale | orderBy:'name'" after-repeat>
[...]
</uib-accordion-group>
</uib-accordion>
变量赋值指令,但它没有做任何事情。
HTML:
var app = angular.module('ZoiglApp', ['ngAnimate', 'ui.bootstrap', 'ngRoute', 'ngTouch', 'leaflet-directive']);
app.config(function($routeProvider) {
$routeProvider
[...]
.when('/search/:searchterm', {
controller: 'SearchController',
controllerAs:'searchctrl',
templateUrl: 'views/search.html'
})
.otherwise({
redirectTo: '/home'
});
});
app.js(带有我的SearchController的控制器):
app.directive('afterRepeat', function() {
return {
restrict: 'A',
link: function(scope, elem, attrs) {
if(scope.$last) {
scope.searchctrl.results = angular.element('.panel').length;
}
}
};
});
afterRepeat.js:
var modalcontent = data.getValue(row, 0);
$("#inputId").html(modalcontent);
编辑:我还在寻找解决方案。我已经回答了以下两条建议,并解决了我们遇到的问题。如果有人试图找到我的错误,那将是非常好的
答案 0 :(得分:1)
只需在控制器中的另一个列表中过滤您的列表,然后在视图中使用这个新列表。
$scope.filteredLokale = $filter('filter')($scope.lokale, { param: "paramValue" });
之后,使用“length”参数计数。
<uib-accordion close-others="true">
<uib-accordion-group is-open="isopen" ng-repeat="lokal in filteredLokale | orderBy:'name'" >
[...]
</uib-accordion-group>
</uib-accordion>
{{ filteredLokale .length }}
答案 1 :(得分:0)
您应该为{% if app.user and is_granted('ROLE_ADMIN') %}
You are logged in and you're an administrator. You can remove is_granted() if you don't need to check for a specific role. This is just a full example.
{% else %}
Please register.
{% endif %}
功能创建角度过滤器,而不是使用public class ImageAdapter extends BaseAdapter {
private Context mContext;
Integer [] imageIDs;
public ImageAdapter(Context c, int ...pos){
mContext = c;
imageIDs = new Integer[pos.length];//it's for set the number items
for (int i=0; i<pos.length; i++){
if (i<mThumbIds.length-1){
imageIDs[i]=mThumbIds[pos[i]];
}
}
//_____________________________
}
private Integer[] mThumbIds = {
R.drawable.alemania_2006, R.drawable.arg_1978, R.drawable.brasil_2014,
R.drawable.francia_1998, R.drawable.rusia_2018, R.drawable.sudafrica_2010
};
@Override
public int getCount() {
return imageIDs.length;
}
@Override
public Object getItem(int position) {
return imageIDs[position];
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null){
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(350, 350));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(4, 4, 4, 4);
}else{
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
}
public class Playing extends AppCompatActivity{
int []img={0,1,2,3,4,5};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_playing);
GridView gridview = (GridView) findViewById(R.id.gridView);
gridview.setAdapter(new ImageAdapter(this, img));
gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(Playing.this, "" + position, Toast.LENGTH_SHORT).show();
//cambiar de vista la imagen al clickear:
}
});
}
}
。然后,您可以将过滤后的数组分配给名为searchFilter
的变量,如此
ng-if