我正在使用 material-ui react 库来渲染一些下拉菜单,使用<FormControl>
,<Select>
和<MenuItem>
组件。这个下拉菜单的选项数组非常大,我想在下拉菜单上设置一个最大高度,所以它不会变得很大。我目前正在努力做到这一点,我将在下面解释。
使用 material-ui 的基本下拉菜单:
const MenuValidNotes = ({
schedule,
indexTrack,
indexSchedule,
actionSetTrackScheduleItemNote,
}) => {
const listNotesMenu = () => (
ARRAY_VALID_NOTES.map((noteObj, i) => (
<MenuItem
value={noteObj.note}
key={`track-item-${indexTrack}-schedule-${indexSchedule}-note-${i}`}
onClick={() => actionSetTrackScheduleItemNote(indexTrack, indexSchedule, noteObj.midiNumber)}
>{noteObj.note}</MenuItem>
))
)
return(
<div>
<FormControl>
<InputLabel>Note</InputLabel>
<Select
defaultValue={noteValueToNoteObject(schedule.noteValue).note}
>
{listNotesMenu()}
</Select>
</FormControl>
</div>
)
}
Run Code Online (Sandbox Code Playgroud)
我发现设置 max-height 的一种方法是<Select>
在 div 中呈现子元素,给它一个类名并对其应用一些 CSS。
但是,该<Select>
组件要求它的子组件是<MenuItem>s
,所以有一个<div>
around 会破坏value
属性,这意味着它不会显示正确的值。(在阅读Material-UI 时发现这个Select …
我使用 Flask 作为我服务器的框架,在返回响应时出现以下错误:
> Traceback (most recent call last):
File "C:\Python27\lib\site-packages\flask\app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Python27\lib\site-packages\flask\app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Python27\lib\site-packages\flask_restful\__init__.py", line 480, in wrapper
resp = resource(*args, **kwargs)
File "C:\Python27\lib\site-packages\flask\views.py", line 84, in view
return self.dispatch_request(*args, **kwargs)
File "C:\Python27\lib\site-packages\flask_restful\__init__.py", line 595, in dispatch_request
resp = meth(*args, **kwargs)
File "rest.py", line 27, in get
return jsonify(**solution)
File "C:\Python27\lib\site-packages\flask\json.py", line 263, in jsonify
(dumps(data, indent=indent, separators=separators), '\n'),
File "C:\Python27\lib\site-packages\flask\json.py", line 123, in dumps
rv …
Run Code Online (Sandbox Code Playgroud) 这是我的代码
class MusicHandler(object):
""" Implements the logic to download musics """
def __init__(self):
""" Creates the class object, loads configs, absolute paths and create directories. Does not init download """
# create logger
self.logger = getLogger("music logger")
self.logger.info("Initializing MusicHandler class object")
# load config vars
self.configs = utils.get_configs()
# load absolute paths
self.dir_music = self.configs["music_path"]
self.dir_audio = utils.get_path_from_rel(self.configs["audio_path"], base_path=self.dir_music)
self.dir_video = utils.get_path_from_rel(self.configs["video_path"], base_path=self.dir_music)
self.taboo_path = utils.get_path_from_rel(self.configs["taboo_path"])
# make dir if not exists
list(map(utils.make_dir_safe, (self.dir_music, self.dir_audio, self.dir_video)))
@run_safe
def download_one(self, link, …
Run Code Online (Sandbox Code Playgroud)我有一个 docker-compose 文件,它创建 3 个 Hello World 应用程序并使用 nginx 来负载平衡不同容器之间的流量。
docker-compose 代码如下:
version: '3.2'
services:
backend1:
image: rafaelmarques7/hello-node:latest
restart: always
backend2:
image: rafaelmarques7/hello-node:latest
restart: always
backend3:
image: rafaelmarques7/hello-node:latest
restart: always
loadbalancer:
image: nginx:latest
restart: always
links:
- backend1
- backend2
- backend3
ports:
- '80:80'
volumes:
- ./container-balancer/nginx.conf:/etc/nginx/nginx.conf:ro
Run Code Online (Sandbox Code Playgroud)
我想验证该restart: always
政策是否确实有效。
我尝试的方法如下:
docker-compose up
;docker container ps
;标识容器 IDdocker stop ID_Container
或杀死/停止其中一个容器docker kill ID_Container
。我期待在第 3 步之后(停止/杀死容器。这使它与代码 137 一起存在),重新启动策略将启动并再次创建一个新容器。
然而,这不会发生。我读到这是故意的,因为有一种方法可以手动停止具有重启策略的容器。
尽管如此,我想知道如何以触发重启策略的方式杀死容器,以便我可以实际验证它是否正常工作。
感谢您的帮助。
我尝试安装和运行amp-paywall-demo
AmpProject GitHub 存储库中提供的示例失败:https://github.com/ampproject/samples/tree/master/amp-paywall-demo \n我已经在那里提出了问题票,但没有收到任何回复到目前为止(https://github.com/ampproject/samples/issues/211)
我尝试遵循安装指南:我克隆了存储库(这按预期工作),但npm install
不幸的是失败了。
我尝试自己调试该错误,但无法做到这一点。 \n我还用 google 搜索了该错误,并在 Git 存储库中的问题中搜索了类似的问题,但这也没有帮助。
\n\n我使用错误的输出以及 debug.log 文件创建了公共要点
\n\n\n\n调试:https://gist.github.com/rafaelmarques7/707f1932f63cd042cdf1e6952c1093ab
\n\n错误堆栈如下:
\n\n\xe2\x9e\x9c amp-paywall-demo git:(master) \xe2\x9c\x97 sudo npm i\n\n> grpc@0.14.1 install /home/rafael/proj/tuts/amp-publisher-sample/amp-paywall-demo/node_modules/gcl\noud/node_modules/grpc\n> node-pre-gyp install --fallback-to-build\n\nnode-pre-gyp info it worked if it ends with ok\nnode-pre-gyp verb cli [ \'/usr/bin/node\',\nnode-pre-gyp verb cli \'/home/rafael/proj/tuts/amp-publisher-sample/amp-paywall-demo/node_modules/\ngcloud/node_modules/grpc/node_modules/.bin/node-pre-gyp\',\nnode-pre-gyp verb cli \'install\',\nnode-pre-gyp verb cli \'--fallback-to-build\' ]\nnode-pre-gyp info using node-pre-gyp@0.6.28\nnode-pre-gyp info using node@10.15.1 | linux | …
Run Code Online (Sandbox Code Playgroud) 我正在尝试了解 Cython,并且我正在关注官方文档。最近,我尝试做“ http://docs.cython.org/en/latest/src/tutorial/profiling_tutorial.html ”中提供的教程。这里的目标是分析 Cython 文档。这就是我遇到麻烦的地方。
要配置文件的函数是(文件“calc_pi.py”):
def recip_square(i):
return 1./i**2
def approx_pi(n=10000000):
val = 0.
for k in range(1,n+1):
val += recip_square(k)
return (6 * val)**.5
Run Code Online (Sandbox Code Playgroud)
分析函数的脚本(如文档中所述)是:
import pstats, cProfile
import calc_pi
cProfile.runctx("calc_pi.approx_pi()", globals(), locals(), "Profile.prof")
s = pstats.Stats("Profile.prof")
s.strip_dirs().sort_stats("time").print_stats()
Run Code Online (Sandbox Code Playgroud)
我不确定要运行哪个命令,以及这是否会引发错误。但是,在他们的页面中,没有提到 thisi。所以我只是运行“python3 profile.py”,这会产生以下错误:
AttributeError: 模块“cProfile”没有属性“runctx”
我知道我的错误可能是愚蠢和最小的,但是在谷歌搜索并检查 stackoverflow 一段时间后,我找不到答案。
感谢您的帮助。
我有一个生产环境,配置为具有指向负载均衡器的域名。这已经可以工作了,并且是使用 Route53 配置的。
我正在使用 Terraform 部署基础设施,包括 Route53 记录。
Route53 记录是手动设置的。
我希望 Terraform 在后续部署中管理 Route53 记录。但是,当我运行更新来更新基础设施并包含 Route53 记录时,出现以下错误:
Error: Error applying plan:
1 error(s) occurred:
* module.asg.aws_route53_record.www: 1 error(s) occurred:
* aws_route53_record.www: [ERR]: Error building changeset:
InvalidChangeBatch: [Tried to create a resource record set
[name='foo.com.', type='A'] but it already exists]
Run Code Online (Sandbox Code Playgroud)
嗯,首先,这个错误是有道理的,因为资源已经存在。但是,鉴于此,如何在不导致停机的情况下解决这个问题呢?
我尝试手动编辑状态文件以包含route53记录,但失败并出现相同的错误...
如有必要,我很乐意提供更多信息。欢迎您提出任何建议。谢谢。
我正在尝试通过ajax
请求将客户端与服务器连接。
我的客户端在 上运行localhost:8080
,有一个按钮调用一个函数,该函数ajax
对本地运行的服务器localhost:5000
.
点击功能:
handleClick() {
console.log("check flights button was clicked!");
console.log(this.state);
const baseUrl = 'localhost:5000'
ajax.get(`${baseUrl}/flights/${this.state.origin}_${this.state.destination}`)
.end((error, response) => {
if (!error && response) {
console.log('got a valid response from the server')
} else {
console.log(`Error fetching data from the server: `, error)
}
});}
Run Code Online (Sandbox Code Playgroud)
使用 实现的(非常)简单的服务器Flask
如下:
from flask import Flask, request
from flask_restful import Resource, Api
from json import dumps
app = Flask(__name__)
api = Api(app)
class Flights(Resource): …
Run Code Online (Sandbox Code Playgroud)