我有以下组件
const list = (props) => {
const handler = function(){
};
var listItems = props.items.map(function(item, index){
return (
<li key={index} onClick={ handler }>
{item.text}
</li>
)
});
return (
<div>
<ul>
{listItems}
</ul>
</div>
)
}
Run Code Online (Sandbox Code Playgroud)
点击我想要点击li的索引.使用ES6而不绑定我该怎么办?
我正在使用由linter eslint-plugin-react解析的以下代码。它返回警告:
“道具验证中缺少产品”
当我在底部的propTypes中声明product时,我将其传递给函数。任何的想法 ?
import React from 'react'
const ProductDesc = (props)=>({
render(){
return (
<div>
<h1>{props.product.headline}</h1>
<img src={props.product.images[0].imagesUrls.entry[2].url} alt="Thumbnail large pic"/>
<p>Yeah</p>
</div>
)
}
})
ProductDesc.propTypes = {
product: React.PropTypes.object
};
export default ProductDesc;
Run Code Online (Sandbox Code Playgroud) 我试图让点击的元素自动定位在屏幕的中心。该列表有一个水平滚动,其中一些overflow-x : scroll隐藏了 div(screen) 之外的内容。我不知道要传递给什么坐标scrollLeft()。
$('#timepicker li').on('click',function(){
var maxScrollLeft= $("#timepicker").scrollLeft('#timepicker').prop('scrollWidth') - $("#timepicker").width();
$('#timepicker').animate({
scrollLeft:
});
});
Run Code Online (Sandbox Code Playgroud)
请看我的codepen:codepen
谢谢你。
我有以下代码来计算字符串中的特殊字符数...不知何故它不会返回我想要的内容
var sectionToCheck = $('input').val(); //it could be any kind of string entered in an input field such as "Hello @&% everybody"
var specialChars = /^[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]*$/;
var allFoundCharacters = sectionToCheck.match(specialChars);
console.log(allFoundCharacters);
Run Code Online (Sandbox Code Playgroud)
它为变量allFoundCharacters返回一个空值.有什么提示吗?