如果我有对象文字:
{a: "hello"}
Run Code Online (Sandbox Code Playgroud)
是否有一个 Javascript 函数可以将此对象转换为文字字符串,以便输出将是文字语法:
'{a: "hello"}'
Run Code Online (Sandbox Code Playgroud)
随着JSON.stringify输出会
'{"a": "hello"}'
Run Code Online (Sandbox Code Playgroud) 我正在通过数组映射,并且为每个项目显示一个带有文本的按钮。假设我希望单击按钮,下面的文本会将其颜色更改为红色。如何定位按钮的同级?我尝试使用ref,但是由于它是映射的jsx,因此只会声明最后一个ref元素。
这是我的代码:
class Exams extends React.Component {
constructor(props) {
super()
this.accordionContent = null;
}
state = {
examsNames: null, // fetched from a server
}
accordionToggle = () => {
this.accordionContent.style.color = 'red'
}
render() {
return (
<div className="container">
{this.state.examsNames && this.state.examsNames.map((inst, key) => (
<React.Fragment key={key}>
<button onClick={this.accordionToggle} className="inst-link"></button>
<div ref={accordionContent => this.accordionContent = accordionContent} className="accordionContent">
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Aperiam, neque.</p>
</div>
</React.Fragment>
))}
</div>
)
}
}
export default Exams;
Run Code Online (Sandbox Code Playgroud)
如所解释的,结果是在每次单击按钮时,将定位到最后一个按钮所附的段落。
提前致谢
我希望我的本地分支与远程分支相同。当我从远程分支中拉取时,我遇到了冲突,在这种情况下,我不想解决它们而只想从远程分支获取最新版本。
我在本地分支中使用硬拉:
git reset -- hard
git pull
Run Code Online (Sandbox Code Playgroud)
然而,当拉我得到错误:
Automatic merge failed; fix conflicts and then commit the result.
Run Code Online (Sandbox Code Playgroud)
为什么?如何通过覆盖拉动远程分支?我想到了一种解决方法,即删除我的本地分支并创建一个新分支然后拉取,但是有更好的方法吗?
我总是在我的应用程序和真实设备上使用调试器,但今天它突然停止工作了。打开它时,我的终端中出现此错误:
Error: Unable to resolve module `./debugger-ui/debuggerWorker.cff11639.js` from ``:
None of these files exist:
* debugger-ui\debuggerWorker.cff11639.js(.native|.native.js|.js|.native.json|.json|.native.ts|.ts|.native.tsx|.tsx)
* debugger-ui\debuggerWorker.cff11639.js\index(.native|.native.js|.js|.native.json|.json|.native.ts|.ts|.native.tsx|.tsx)
at ModuleResolver.resolveDependency (C:\Presto\Frontend 19-5\node_modules\metro\src\node-haste\DependencyGraph\ModuleResolution.js:163:15)
at ResolutionRequest.resolveDependency (C:\Presto\Frontend 19-5\node_modules\metro\src\node-haste\DependencyGraph\ResolutionRequest.js:52:18)
at DependencyGraph.resolveDependency (C:\Presto\Frontend 19-5\node_modules\metro\src\node-haste\DependencyGraph.js:287:16)
at C:\Presto\Frontend 19-5\node_modules\metro\src\lib\transformHelpers.js:267:42
at Server.<anonymous> (C:\Presto\Frontend 19-5\node_modules\metro\src\Server.js:841:41)
at Generator.next (<anonymous>)
at asyncGeneratorStep (C:\Presto\Frontend 19-5\node_modules\metro\src\Server.js:99:24)
at _next (C:\Presto\Frontend 19-5\node_modules\metro\src\Server.js:119:9)
Run Code Online (Sandbox Code Playgroud)
打开调试器后,应用程序卡住了,我无法按任何东西。有什么我可以做的吗?我试过
gradlew clean
Run Code Online (Sandbox Code Playgroud)
但这没有帮助。我使用的是 Android 和 Windows 10。
我安装了最新版本的 nginx 并配置了一些目录:
./configure --sbin-path=/usr/bin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-pcre --pid-path=/var/run/nginx.pid --with-http_ssl_module
Run Code Online (Sandbox Code Playgroud)
一切正常。之后我创建了一个自定义文件:
nano /lib/systemd/system/nginx.service
Run Code Online (Sandbox Code Playgroud)
文件内容:
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/bin/nginx -t
ExecStart=/usr/bin/nginx
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
但是当运行“systemctl start nginx”时,我收到错误“未找到单元”:
我不明白为什么或有什么问题。运行“nginx -V”显示目录已设置。
有人有线索吗?提前致谢
虽然看起来很简单我做不到,但我希望这两个按钮从两侧相互接触并水平居中,如下所示:
我在这个线程中尝试了答案:水平居中两个按钮,但它只与 RelativeLayout 而不是 ContrainstLayout 有关
我也试着玩
app:layout_constraintHorizontal_chainStyle="spread"
Run Code Online (Sandbox Code Playgroud)
但没有成功。我没有帮助的 xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBackground"
tools:context=".MainActivity">
<Button
android:id="@+id/button"
style="@style/btnStyle"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:background="@color/btnTrue"
android:text="Button"
android:textColor="#ffffff"
app:layout_constraintEnd_toStartOf="@+id/button2"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button2"
style="@style/btnStyle"
android:layout_height="wrap_content"
android:layout_marginEnd="56dp"
android:background="@color/btnFalse"
android:text="Button"
app:layout_constraintEnd_toEndOf="parent"
tools:layout_editor_absoluteY="0dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
这可以通过 ConstraintLayout 实现吗?
每当我使用useState或具有相同结构的类似函数时,如果我只需要使用数组函数,我就会收到 lint 错误,例如:
const [searchParams, setSearchParams] = useSearchParams();
Run Code Online (Sandbox Code Playgroud)
如果我只需要使用setSearchParams,而不需要使用searchParams,lint 会显示一个错误,指出第一个从未使用过。
替换searchParams为 null 或 undefined 会引发其他错误。有没有办法在语法中解决这个问题?(不改变 lint 配置)
我知道这个主题显然已经讨论了很多,但我不确定如何研究我的问题,我的问题相当具体,我希望它遵循这里的规则。
我知道要决定是否更新 DOM,react 会将虚拟 DOM 与重新渲染的 DOM 进行比较。但我只是不明白它是否决定更新它 - 它是否更新特定重新渲染组件的所有元素,或者它是否知道只更新组件中已更改的元素?
提前致谢,
我将一个按钮限制在屏幕底部,但不幸的是,屏幕底部边框和按钮底部边框之间有一个小间隙:
我的 XML:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.tabs.TabLayout
android:id="@+id/navigationTabs"
android:layout_width="match_parent"
android:layout_height="100dp"
app:layout_constraintTop_toTopOf="parent"
app:tabMinWidth="100dp"
app:tabRippleColor="@null"
/>
<Button
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="BUTTON"
android:layout_margin="0dp"
app:layout_constraintBottom_toBottomOf="parent"/>
<LinearLayout
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/navigationTabs" />
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
造成这种差距的原因是什么?我怎样才能摆脱它?
我有一个类型:
export type MyType = 'something' | 'another' | 'else';
Run Code Online (Sandbox Code Playgroud)
然后我想使用它的一些选项:
Interface MyInterface {
selection: Pick<MyType, 'something' | 'another'>
}
Run Code Online (Sandbox Code Playgroud)
但出现错误type doesn't satisfy the constraint
难道不能在类型上使用 Pick 而只能在接口上使用吗?
reactjs ×3
android ×2
javascript ×2
css ×1
eslint ×1
git ×1
json ×1
nginx ×1
react-native ×1
ref ×1
systemctl ×1
typescript ×1
virtual-dom ×1