我有这个:
map = ranks.map((row, r) => (
row.map((rank, i) => {
return [element(r, i, state, rank, toggled, onClick)];
})
));
Run Code Online (Sandbox Code Playgroud)
它通过二维数组进行映射.在每一行之后,我想插入<div class="clearfix"></div>.
我想,如果我能以某种方式得到每一行的最后一个索引,那么我将能够在行映射回调中使用它.有人可以告诉我该怎么做吗?
我不知道我是否正确地执行此操作...如果我想从输入中获取值,我使用this.refs.whatever.value.trim()但是如果该输入是无状态函数组件,我该怎么办检索onSubmit的值?
我知道在研究之后现在这是不正确的,但是你应该如何从这些输入字段中获得价值呢?
import React, {Component} from 'react'
import {InputField} from '../components/forms/InputField'
import {Button} from '../components/forms/Button'
export default class SignupWrapper extends Component {
_handleSubmit(e) {
e.preventDefault();
const email = this.refs.email.value.trim();
const password = this.refs.password.value.trim();
const confirm = this.refs.confirm.value.trim();
console.log({email, password, confirm});
}
render() {
return (
<form id="application-signup" onSubmit={this._handleSubmit.bind(this)}>
<InputField type={'email'} name={'email'} text={'email'}
helpBlock={'email is required'} ref="email" />
<InputField type={'password'} name={'password'} text={'password'}
helpBlock={'password is required'} ref="password" />
<InputField type={'password'} name={'confirm'} text={'confirm password'}
helpBlock={'password confirmation is required'} ref="confirm" />
<Button type={'submit'} className={'btn …Run Code Online (Sandbox Code Playgroud) 我有一个包含一堆ReactList组件的组件.ReactList组件是一个执行无限滚动的组件,即只加载视口上的内容.它有几种模式:简单和统一.我正在使用简单的,只是在向下滚动时加载和加载(使可滚动页面更长).统一加载并删除现在超出视口的上述部分.我尝试使用统一模式,如果它有效,我甚至不需要问我将要做什么,但它是超级越野车并且失败了目的.简单的另一方面是超快速滚动和加载同样快.
我将我的列表分解为几个用户可以单击的组,它将加载该ReactList组件.如果可滚动页面很短,即用户没有完全滚动,则在列表组之间进行更改是足够快的.〜2秒.但是,如果页面一直向下滚动,并且尝试更改列表需要大约6秒.
我注意到页面也已完全加载,即无需加载.好吧,我想也许如果我更改了包装器父组件的密钥并只重新安装组件,它应该是快速的吗?不.重新加载的组件很短,只有一个视口长度,但需要大约5秒.
我注意到将完全加载的列表组件页面更改为常规单行文本"Hello world"组件仍然需要大约相同的数量!〜5秒.那是怎么回事?
问题:为什么卸载列表中包含许多小组件的长页面需要很长时间才能卸载?
对不起,我意识到这篇文章很长很充满,但我想我应该解释一下我的情况.
我将我的本地数据库移到了 mLab 的免费层,但我收到了以前没有遇到的错误。 ParallelSaveError: Can't save() the same doc multiple times in parallel
错误是从 line 捕获的user.save()。你能看一下,请说明如何修复它吗?我好失落...
// Confirm password.
// Execs after requiresAuth permission resolver.
const confirmPassword = ({ user, inputs: { password } }) => {
// Validate args.
validate([required, isLength], 'PASSWORD', password)
// Required for graphql. Expects a promise.
return new Promise((resolve, reject) =>
user.comparePassword(password, (err, isMatch) => {
if (err) return reject(err)
if (!isMatch) return reject(error('CONFIRM_PASSWORD_FAILED'))
return resolve(user)
})
)
}
Run Code Online (Sandbox Code Playgroud)
// Compare submitted plain …Run Code Online (Sandbox Code Playgroud) 假设我有一个域example.com。我通过托管和 cli 创建了第二个网站sub.example.com。
{
"hosting": [
{
"target": "app",
"public": "public",
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
},
{
"target": "promos",
"public": "public",
"appAssociation": "AUTO",
"rewrites": [
{
"source": "**",
"dynamicLinks": true
}
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
现在,当我在sub.example.com没有任何路径前缀的情况下创建动态链接时,它给了我一个危险信号:
It looks like you already have content served on this path. Specify a different path prefix to avoid conflicts with existing content.
Run Code Online (Sandbox Code Playgroud)
public字段吗?我不想在上面显示任何内容,只是链接...我阅读了“使用效果钩子”文档,但我仍然很难清除useEffect钩子的副作用。具体来说,我有这个类组件,我想了解如何使用useEffect钩子将其转换为函数组件。
class Alert extends PureComponent {
componentDidMount() {
this.handleSetTimeout()
}
componentDidUpdate() {
this.handleClearTimeout()
this.handleSetTimeout()
}
componentWillUnmount() {
this.handleClearTimeout()
}
handleSetTimeout = () => {
const { alert: { id, ttl }, handlePopAlert } = this.props
if (!ttl) return
this.timeout = setTimeout(() => handlePopAlert(id), ttl)
}
handleClearTimeout = () => {
if (!this.timeout) return
clearTimeout(this.timeout)
this.timeout = null
}
render() { return (...) }
}
Run Code Online (Sandbox Code Playgroud) 假设我有两个字符串变量:
a = 'LOVE';
b = '....';
Run Code Online (Sandbox Code Playgroud)
我如何使用正则表达式(或其他最快的)来组合a + b来制作:
c = 'L.O.V.E.';
Run Code Online (Sandbox Code Playgroud)
在我的情况下,两个字符串总是长4个字符,第二个字符串不是固定字符,我只是使它成为一个点,使其在屏幕上看起来更清晰.
我有一个对象:
let object1 = { a: 'one', b: 'two', c: 'three' };
Run Code Online (Sandbox Code Playgroud)
我正在尝试将object1.a设置为object2的键:
object2 = { key: 'something' };
Run Code Online (Sandbox Code Playgroud)
我试图把钥匙作为:
[object1].a
object1.a
object1[a]
Run Code Online (Sandbox Code Playgroud)
我记得我必须使用括号表示法,但无法弄清楚如何做到这一点?
我想这样做的原因是因为我要根据道具改变object1的值,所以我可以只根据收到的道具改变一个组件.
很抱歉,如果这是一个愚蠢的问题,但我遇到了用C编写的这行代码,这让我很困惑来自JavaScript背景.
short s;
if ((s = data[q])) return s;
Run Code Online (Sandbox Code Playgroud)
这是为数据[q]分配s,如果它等于true/1则返回s?
我有一个像这样的JSON文件:
data.json
{
"ABCD": [ ["x", "x", "x", "x"], ["x", "x", "x", "x"] ],
"EFGH": [ ["x", "x", "x", "x"], ["x", "x", "x", "x"] ],
"IJKL": [ ["x", "x", "x", "x"], ["x", "x", "x", "x"] ]
}
Run Code Online (Sandbox Code Playgroud)
我想遍历键A1,B1,C1等,并重新写入data.json文件,如下所示:
{
"ABCD": [ ["Ax", "Bx", "Cx", "Dx"], ["Ax", "Bx", "Cx", "Dx"] ],
"EFGH": [ ["Ex", "Fx", "Gx", "Hx"], ["Ex", "Fx", "Gx", "Hx"] ],
"IJKL": [ ["Ix", "Jx", "Kx", "Lx"], ["Ix", "Jx", "Kx", "Lx"] ]
}
Run Code Online (Sandbox Code Playgroud)
我该怎么做?我之前从未使用过Ruby ...但我想从一些有用的脚本开始学习.
javascript ×4
reactjs ×3
arrays ×1
c ×1
express ×1
firebase ×1
json ×1
mongoose ×1
node.js ×1
passport.js ×1
react-hooks ×1
regex ×1
ruby ×1