小编Elw*_*wyn的帖子

按出现次数对数组进行分组,并使用Lodash对其进行排序

如果有这个数组:

[
  {
    "name" : "lala",
    "source_ip" : "10.10.10.10"
  },
  {
    "name" : "lulu",
    "source_ip" : "10.10.10.11"
  },
  {
    "name" : "lolo",
    "source_ip" : "10.10.10.10"
  }
]
Run Code Online (Sandbox Code Playgroud)

我想按事件分组并使用Lodash对其进行排序以获得此结果:

[
  {
    "source_ip" : "10.10.10.10",
    "count" : 2
  },
  {
    "source_ip" : "10.10.10.11",
    "count" : 1
  },
]
Run Code Online (Sandbox Code Playgroud)

这是我尝试过的:

app.filter('top10', function() {
  return function(incidents) { 
    return _.chain(incidents)
        .countBy("source_ip")
        .value();
  };
});
Run Code Online (Sandbox Code Playgroud)

我也试过减少之前然后使用grouBy但它不起作用.

非常感谢.

javascript angularjs lodash

5
推荐指数
1
解决办法
1170
查看次数

Angular 7 - 不同视图中的搜索栏和结果

我创建了两个组件:

  • search-bar.component.ts : 显示在所有视图中
  • search.component.ts : 应该显示结果(来自 REST API 的响应)

工作是这样的:在应用程序的任何地方,我都想执行全局搜索(产品、用户、事件等...)。我在搜索栏中写了一些东西,点击搜索,然后我被重定向到结果页面。结果是从 REST API 获取的。

PS:我在互联网上搜索了几个小时,但没有找到..奇怪!我已经阅读了很多关于@Input并且@Output确实如此。

我接近实现我想要的,用这种代码:

import { Component, OnInit } from '@angular/core';
import {Router} from '@angular/router';

@Component({
  selector: 'app-search-bar',
  templateUrl: './search-bar.component.html',
  styleUrls: ['./search-bar.component.css']
})
export class SearchBarComponent implements OnInit {
  constructor(
    private router: Router
  ) { }

  ngOnInit() {
  }

  onSubmit(search: string, from: string, to: string) {
    this.router.navigate(['recherche'], {
      queryParams: {
        search: search,
        from: from,
        to: to
      }
    });
  }

}
Run Code Online (Sandbox Code Playgroud)

表格是这样构建的:<form ngNoForm class="form-inline"> …

rest search angular

5
推荐指数
1
解决办法
2万
查看次数

在使用 MongoDB 和 Golang 进行查找的引用中获取值

我有下面的结构。我使用Golang 1.9.2

// EventBoost describes the model of a EventBoost
type EventBoost struct {
  ID          string    `bson:"_id" json:"_id" valid:"alphanum,printableascii"`
  CampaignID  string    `bson:"_campaign_id" json:"_campaign_id" valid:"alphanum,printableascii"`
  Name        string    `bson:"name" json:"name"`
  Description string    `bson:"description" json:"description"`
  Level       string    `bson:"level" json:"level"`
  EventID     string    `bson:"_event_id" json:"_event_id" valid:"alphanum,printableascii"`
  StartDate   time.Time `bson:"start_date" json:"start_date"`
  EndDate     time.Time `bson:"end_date" json:"end_date"`
  IsPublished bool      `bson:"is_published" json:"is_published"`
  CreatedBy   string    `bson:"created_by" json:"created_by"`
  CreatedAt   time.Time `bson:"created_at" json:"created_at"`
  ModifiedAt  time.Time `bson:"modified_at" json:"modified_at"`
}

// LocationBoost describes the model of a LocationBoost
type LocationBoost struct { …
Run Code Online (Sandbox Code Playgroud)

go mongodb mgo

4
推荐指数
1
解决办法
2230
查看次数

是否可以阻止AngularJS应用程序在工作时间启动?

是否可以阻止AngularJS应用程序在工作时间启动?

假设我不希望应用程序在8h到18h之间工作.在此期间,我想显示一个页面,说明用户必须回来the time left.

angularjs

0
推荐指数
1
解决办法
53
查看次数

标签 统计

angularjs ×2

angular ×1

go ×1

javascript ×1

lodash ×1

mgo ×1

mongodb ×1

rest ×1

search ×1