他们使用此代码检索路由器的参数'id'并使用它来获取service服务的英雄:
ngOnInit() {
this.route.params
.switchMap((params: Params) => this.service.getHero(+params['id']))
.subscribe((hero: Hero) => this.hero = hero);
}
Run Code Online (Sandbox Code Playgroud)
但我不太清楚switchMap在上面的代码中使用运算符的目的是什么.
以下代码不一样?
ngOnInit() {
this.route.params
// NOTE: I do not use switchMap here, but subscribe directly
.subscribe((params: Params) => {
this.service.getHero(+params['id']).then(hero => this.hero = hero)
});
}
Run Code Online (Sandbox Code Playgroud) 我正在使用这个插件来检测Vim中的PEP-8错误和警告:http://www.vim.org/scripts/script.php? script_id = 3430
我想忽略一些错误和警告,如后端pep8工具中给出的E501和W601:http://pypi.python.org/pypi/pep8
当我查看插件代码时,我可以看到它支持这个:
from pep8checker import Pep8Checker
args = vim.eval('string(g:pep8_args)')
select = vim.eval('string(g:pep8_select)')
ignore = vim.eval('string(g:pep8_ignore)')
if select:
args = args + ' --select=%s' % select
if ignore:
args = args + ' --ignore=%s' % ignore
pep8_checker = Pep8Checker(cmd, args)
Run Code Online (Sandbox Code Playgroud)
但是我该如何使用它?
我正在寻找一个可用于实现基于SAML2的服务提供者和身份提供者的Python库.核心库不应该依赖于任何特定的Web框架.我正在寻找功能更齐全,最好易于使用的东西.图书馆也应该有更宽松的许可证(非GPL).搜索后我找到了一些链接,我在这里粘贴了它:
http://wiki.python.org/moin/SAML
有什么建议吗?
考虑以下示例:
postgres=# CREATE TABLE emptyarray (fields jsonb);
CREATE TABLE
postgres=# INSERT INTO emptyarray VALUES ('{"key":["a","b"]}');
INSERT 0 1
postgres=# INSERT INTO emptyarray VALUES ('{"key":[]}');
INSERT 0 1
postgres=# SELECT * from emptyarray where Fields@>'{"key":["b"]}';
fields
---------------------
{"key": ["a", "b"]}
(1 row)
postgres=# SELECT * from emptyarray where Fields@>'{"key":[]}';
fields
---------------------
{"key": ["a", "b"]}
{"key": []}
(2 rows)
Run Code Online (Sandbox Code Playgroud)
在第二个查询中,我期望结果中仅一行(一个记录为空数组)。但是如您所见,结果中有两行。如何使用@>语法查询空数组?
我正在使用PostgreSQL 9.6
如果我在一个http处理程序中启动一个goroutine,它是否会在返回响应后完成?这是一个示例代码:
package main
import (
"fmt"
"net/http"
"time"
)
func worker() {
fmt.Println("worker started")
time.Sleep(time.Second * 10)
fmt.Println("worker completed")
}
func HomeHandler(w http.ResponseWriter, r *http.Request) {
go worker()
w.Write([]byte("Hello, World!"))
}
func main() {
http.HandleFunc("/home", HomeHandler)
http.ListenAndServe(":8081", nil)
}
Run Code Online (Sandbox Code Playgroud)
在上面的例子中,workergoroutine是否会在所有情况下完成?或者是否有任何特殊情况无法完成?
python ×2
angular ×1
go ×1
goroutine ×1
http ×1
javascript ×1
json ×1
observable ×1
pep8 ×1
postgresql ×1
rxjs ×1
saml ×1
sql ×1
vim ×1