我试图找到一种选择除一个特定元素之外的所有元素的方法。在这种情况下,它:not(selector)不起作用。
选择容器内除指定元素之一之外的所有元素的最佳方法是什么?
.container not:(.test2) {
color: red
}Run Code Online (Sandbox Code Playgroud)
<div class='container'>
<p class='test'>test</p>
<p class='test'>test</p>
<p class='test'>test</p>
<p class='test'>test</p>
<p class='test2'>test 2</p>
</div>Run Code Online (Sandbox Code Playgroud)
我\xe2\x80\x99m 试图运行我的python 项目,该项目似乎在我的Mac 上运行良好(在pycharm 中最好,不太好,但可以在VSCode 中运行),但在VSCode 中的树莓派上运行得很糟糕。每当我运行 apipenv shell然后运行 a 时,pipenv install它都会抱怨以下错误:
Pipfile.lock (e9a11d) out of date, updating to (47943b)...\nLocking [dev-packages] dependencies...\nLocking [packages] dependencies...\nBuilding requirements...\nResolving dependencies...\n\xe2\x9c\x98 Locking Failed! \n[ResolutionFailure]: File "/home/nick/.local/lib/python3.7/site-packages/pipenv/resolver.py", line 741, in _main\n[ResolutionFailure]: resolve_packages(pre, clear, verbose, system, write, requirements_dir, packages, dev)\n[ResolutionFailure]: File "/home/nick/.local/lib/python3.7/site-packages/pipenv/resolver.py", line 709, in resolve_packages\n[ResolutionFailure]: requirements_dir=requirements_dir,\n[ResolutionFailure]: File "/home/nick/.local/lib/python3.7/site-packages/pipenv/resolver.py", line 692, in resolve\n[ResolutionFailure]: req_dir=requirements_dir\n[ResolutionFailure]: File "/home/nick/.local/lib/python3.7/site-packages/pipenv/utils.py", line 1403, in resolve_deps\n[ResolutionFailure]: req_dir=req_dir,\n[ResolutionFailure]: File "/home/nick/.local/lib/python3.7/site-packages/pipenv/utils.py", line 1108, in actually_resolve_deps\n[ResolutionFailure]: resolver.resolve()\n[ResolutionFailure]: File "/home/nick/.local/lib/python3.7/site-packages/pipenv/utils.py", line 833, …Run Code Online (Sandbox Code Playgroud) 我已经构建了一个简单的演示(https://codepen.io/anon/pen/VgKQoq),单击按钮时创建的元素和对象:它创建一个元素,然后将该元素的对象推入'对象'阵列.单击"删除"按钮时,将使用ID成功删除元素和对象.
但是,问题是每次删除一个元素时,remove函数有时会运行太多次,具体取决于单击的元素,我不知道为什么.在演示中,打开javascript控制台,创建例如4个元素,然后通过单击remove删除第3个元素,您将看到会发生什么.
有谁知道为什么会这样?我认为这可能是因为事件监听器一次又一次地添加到相同的元素,但它在删除时似乎不起作用.这里有任何解释和最佳实践,谢谢.
var id = 0, objects = [], removes;
function createEntry() {
id++;
// create new element, append to #container & create new object
var container = document.querySelector('#container'),
newEntry = document.createElement("div"),
title = 'title text here',
description = 'description text here',
remove = 'remove',
dataId = id,
obj = new Entry(title, description, remove);
newEntry.classList.add("entry");
newEntry.innerHTML = '<span class="title">' + title + '</span><span class="description">' + description + '</span><span class="remove">' + remove + '</span>';
container.appendChild(newEntry);
newEntry.setAttribute('data-id', id);
updateElements(); …Run Code Online (Sandbox Code Playgroud)我试图让一个功能组件在testFn执行时强制重新渲染。我想使用状态来做到这一点(如果有更好的方法,请大声说出来),这似乎成功地强制重新渲染,但只有两次,然后什么也没有。
我构建了一个简单的演示来模拟该问题,因为使用我的真实应用程序太难演示,但应该应用相同的原则(我的真实演示在函数执行时获取数据并将其显示在页面上,但它没有重新渲染,我有刷新页面以查看新数据,这就是为什么我想触发重新渲染)。
import React, { useState } from "react";
const App = () => {
const [, rerender] = useState(false);
const testFn = () => {
console.log("test Fn");
rerender(true);
};
return (
<div>
<p>test</p>
<button onClick={testFn}>clickk</button>
{console.log("render")}
</div>
);
};
export default App;
Run Code Online (Sandbox Code Playgroud)
为了方便起见,我还制作了一个Stackblitz演示。
任何人都可以解决这个演示或想出更好的实现方法吗?
感谢您在这里的任何帮助。
我是一个相对较新的JavaScript,我试图通过if语句专门讨论ES6语法.我可以创建简单的ES6函数,如:
function test(a,c) {
return a+c;
}
[3,8,-4,3].reduce(test);
Run Code Online (Sandbox Code Playgroud)
但是,如果我想添加if语句,我无法使用ES6语法 - 例如:
function maxValue(a,c) {
if (c >= a) { a == c }
}
[3,8,-4,3].reduce(maxValue);
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用Math方法通过以下方式获得结果:
var array = [267, 306, 108];
var largest = Math.max.apply(Math, array); // returns 306
Run Code Online (Sandbox Code Playgroud)
但我想知道如何正确使用新的ES6语法.我试图在filter,reduce,map和forEach中添加if语句来实现数组中的最高值并且遇到困难.
任何有关初学者材料的帮助,建议或链接都将非常感谢,谢谢.
我有一个 onChange 函数onNameChange,其中包含一个valid应与名称字段的 yup 验证相匹配的变量。问题在于,有效变量仅在提交表单后才显得正确,而在更改名称字段时则不然;我希望在提交之前该信息有效。
如何在更改名称字段而不是提交时获得正确的值?请注意,我发现了类似的帖子,但使用了 Formik,这不是我想要使用的:Formik + 是的:如何在提交之前立即验证表单?
是的设置:
const schema = Yup.object().shape({
name: Yup.string()
.required("Required")
.min(3, "Enter at least 3 characters")
});
const {
register,
handleSubmit,
setError,
formState: { errors },
trigger
} = useForm({
resolver: yupResolver(schema)
// mode: "onTouched",
// reValidateMode: "onChange"
});
Run Code Online (Sandbox Code Playgroud)
改名功能:
const onNameChange = async ({ target: { value } }) => {
const valid = await trigger("name");
console.log("valid", valid, "value", value);
if (!valid) {
// @todo: bug here? …Run Code Online (Sandbox Code Playgroud) 最近,我更改了自定义输入组件以使用 React,useFormContext而不是通过 props 向它们传递errors和组件。register自从这样做以来,我遇到了这个恼人的打字稿错误:
Property 'defaultValue' does not exist on type 'IntrinsicAttributes'
取这部分代码:
<Tag
type={type}
id={title}
{...register(title)}
defaultValue={defaultValue}
placeholder={placeholder}
disabled={disabled}
/>
Run Code Online (Sandbox Code Playgroud)
它仅在 下显示错误defaultValue,但如果我删除它,它会决定在 下显示它placeholder,依此类推(如果删除)。
Tag另外,我注意到通过更改为 不能完美解决问题input,这不好,因为这样我就无法将该组件用于textarea输入等用途。它以前确实有效,我只是使用表单上下文更改了它,所以不知道为什么它不喜欢那样。
有谁知道为什么会出现这个问题?表格的相关部分:
const CreatePageForm: FC<CreatePageFormProps> = ({ createPage, setCreatePageModalIsOpen, loadingCreatePage }) => {
const methods = useForm<PageFormInputs>({
resolver: yupResolver(createPageSchema),
mode: 'onTouched',
});
// const { // was like this commented out before, when it worked
// register,
// handleSubmit,
// …Run Code Online (Sandbox Code Playgroud) .appShopSummaryContainer {
display: flex;
flex-flow: column wrap;
}
.appShopSummaryContainer .appShopSummaryProductWrap {
flex-basis: 100%;
background: pink;
height: 100%;
width: 100%;
display: flex;
flex-flow: row nowrap;
align-items: center;
}
.appShopSummaryContainer .appShopSummaryImg {
flex: 0 0 40%;
height: auto;
padding-bottom: 26.667%;
background: green;
background-size: cover !important;
background-position: center center !important;
}
.appShopSummaryContainer .appShopSummaryInfo {
flex: 0 0 60%;
background: orange;
display: flex;
flex-flow: column wrap;
align-items: flex-start;
height: 100%; /* not working */
/* doesn't work: align-self: stretch; */
}
.appShopSummaryContainer .appShopSummaryMoreInfoBtn { …Run Code Online (Sandbox Code Playgroud)我是 django 的新手,我试图找出为什么通过我的帐户表单创建新帐户不会对密码进行哈希处理(我假设密码没有进行哈希处理,因为在创建帐户时我无法使用密码登录,并且此消息显示在通过表单创建的帐户的 django 管理的密码字段下:)Invalid password format or unknown hashing algorithm。我可以在 django 管理中成功创建不存在此未哈希密码问题的新帐户。
视图.py:
@unauthenticated_user
def create_account(request):
form = AccountForm()
if request.method == 'POST':
form = AccountForm(request.POST)
# should hash the password, check username/email doesnt already exist, etc
if form.is_valid():
user = form.save()
return redirect('/login')
else:
messages.info(request, "Count not create account.")
context = {'form': form}
return render(request, 'accounts/create_account.html', context)
Run Code Online (Sandbox Code Playgroud)
模型.py:
class Account(AbstractUser):
def __str__(self) -> str:
return self.first_name
pass
Run Code Online (Sandbox Code Playgroud)
创建帐户表格:
<form action="{% url 'create_account' %}" method="POST">
{% csrf_token …Run Code Online (Sandbox Code Playgroud) 我在尝试着:
\n我希望能够跑步,npm install并且让一切都完美地运行。
为了更好地解释我的问题,运行npm install返回以下内容:
npm WARN ERESOLVE overriding peer dependency\nnpm WARN While resolving: react-side-effect@1.2.0\nnpm WARN Found: react@18.2.0\nnpm WARN node_modules/react\nnpm WARN react@"^18.2.0" from the root project\nnpm WARN 9 more (@fortawesome/react-fontawesome, ...)\nnpm WARN \nnpm WARN Could not resolve dependency:\nnpm WARN peer react@"^0.13.0 || ^0.14.0 || ^15.0.0 || ^16.0.0" from react-side-effect@1.2.0\nnpm WARN node_modules/react-document-meta/node_modules/react-side-effect\nnpm WARN react-side-effect@"^1.1.0" from react-document-meta@3.0.0-beta.2\nnpm WARN node_modules/react-document-meta\nnpm WARN \nnpm WARN Conflicting peer dependency: …Run Code Online (Sandbox Code Playgroud)