这是我的 React 组件
import React, { Component } from 'react';
import categories from './categories.json'
import './content.css'
export default class Content extends Component {
constructor(props) {
super(props)
this.state = {
searchText: '',
categories
}
}
render() {
return(
<div className="content">
<form className="searchform" onSubmit={this.search}>
<input type="text" name="keyword" id="searchbox" placeholder="Search String"></input>
<select name="categories" id="searchcategories">
<option defaultValue="" defaultChecked>Select a category</option>
{this.state.categories.map(x =>
<option key={x.value} value={x.value}>{x.name}</option>
)}</select>
<input type="submit" value ="Search" id="searchsubmit" />
</form>
</div>
)
}
search(e) {
console.log(e.target)
e.preventDefault();
}
}
Run Code Online (Sandbox Code Playgroud)
单击提交按钮时,我的函数search …
我得到了这种类型的数组,并且我想按整个数组将其仅按一列(first_name)分组,
[
{
first_name: "Apurv",
date: "2018-01-22",
is_present: "1",
}
{
first_name: "Lucky",
date: "2018-01-22",
is_present: "0",
}
{
first_name: "Apurv",
date: "2018-01-20",
is_present: "0",
}
{
first_name: "Lucky",
date: "2018-01-20",
is_present: "1",
}
]
Run Code Online (Sandbox Code Playgroud)
所以我怎么能从“ 组件 ” 按此数组分组?
在 NodeJS 中创建 GRPC 客户端时,如果我使用的是grpc包,我可以使用GRPC_VERBOSITY设置为debug环境变量来启动我的程序。
$ GRPC_VERBOSITY=debug node index.js
Run Code Online (Sandbox Code Playgroud)
我将获得大量有关正在发生的网络通信的信息。
但是,如果我切换出实现并使用该@grpc/grpc-js包,GRPC_VERBOSITY=debug则没有任何效果。
我已经研究了实现 的底层打字稿,@grpc/grpc-js我看到了日志调用的样子。
所以我的问题是:如何在@grpc/grpc-jsNodeJS 中使用NPM 包时启用日志记录
我有以下代码:
package main
import (
"fmt"
"time"
)
func main() {
ch := make(chan int)
ch2 := make(chan int)
go func(c chan int, c2 chan int) {
for {
select {
case v := <-c:
fmt.Println(v)
case v := <-c2:
fmt.Println(v)
default:
}
}
}(ch, ch2)
ch <- 1
close(ch)
close(ch2)
time.Sleep(10 * time.Second)
}
Run Code Online (Sandbox Code Playgroud)
当我运行此命令时,它会打印1到标准输出,然后继续打印0。为什么是这样?
我知道我可以在goroutine中检查通道是否关闭,但是我只是想知道原因。
另外,假设我要在关闭所有(多个)通道后从goroutine退出,这可能吗?我以为一旦关闭了所有通道,在所有通道都关闭后,在默认情况下我有可能退出goroutine