数据:
我有数据内部数组,我尝试循环默认代码:
<div className="loop-container">
{
joblist.map((itemb,index) => (
<div>
</div>
))
}
</div>
Run Code Online (Sandbox Code Playgroud)
我想首先显示该数组的名称,(这是日期)然后显示这个数组包含的内容,但是我收到错误:
joblist.map不是一个函数
我尝试按设定日期过滤数组
var di = new Date(this.state.date.slice(0, 4),
this.state.date.slice(5, 7),
this.state.date.slice(8, 10),
'10',
'00');
var result2 = result.filter(function(number) {
return (number[2] == di)
});
Run Code Online (Sandbox Code Playgroud)
但结果是一个空数组 ( result2)。
console.log(di)下面是数组的一个元素的屏幕截图-
尝试使用裁纸器组件创建上传功能。但是当我尝试设置状态时说
未捕获的TypeError:this.setState不是FileReader.reader.onload的函数
零件
import React, { Component, PropTypes } from 'react'
import { Link, browserHistory } from 'react-router'
import { connect } from 'react-redux'
import Cropper from 'react-cropper';
class HeadPortrait extends Component {
constructor(props) {
super(props)
this.state = {
image: '',
}
}
clickadd(e) {
document.getElementById('uploadfiles').click();
}
loadFile(e) {
e.preventDefault();
var reader = new FileReader();
reader.onload = function () {
this.setState({ image: reader.result })
};
reader.readAsDataURL(e.target.files[0]);
;
};
_crop() {
// image in dataUrl
console.log(this.refs.cropper.getCroppedCanvas().toDataURL());
}
render() { …Run Code Online (Sandbox Code Playgroud) 尝试渲染元素列表,但浏览器返回类似的内容。在我观看的教程中,返回“li”元素,但我不知道为什么它返回这个
<div id="root">
<div data-reactroot="">
<ul>
<contact name="vasya"></contact>
<contact name="Petya"></contact>
<contact name="Killa"></contact>
<contact name="Pedro"></contact>
</ul>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
需要返回“li”元素
我是 React 新手,所以不知道为什么会发生我的代码
var contacts = [
{
id: 1,
name: "vasya",
phone: "0989893"
},
{
id: 2,
name: "Petya",
phone: "0986666"
},
{
id: 31,
name: "Killa",
phone: "09833333"
},
{
id: 4,
name: "Pedro",
phone: "09833434"
},
]
var contact = React.createClass({
render: function () {
return(
<li> {this.props.name}</li>
);
}
});
var ContactList = React.createClass({
render: function() {
return …Run Code Online (Sandbox Code Playgroud) 尝试使用axios在Ajax请求中设置标头
import React, { Component, PropTypes } from 'react'
import { Link, browserHistory } from 'react-router'
import { connect } from 'react-redux'
import axios from 'axios'
class Income extends Component {
constructor(props) {
super(props)
this.state = {
};
}
componentDidMount() {
axios.post('http://139.196.141.166:8084/course/income/outline', {
headers: { 'X-Authenticated-Userid': '15000500000@1' }
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
}
render() {
return (
<div>
dsdss
</div>
)
}
Run Code Online (Sandbox Code Playgroud)
但服务器返回我,我没有设置标题.我在文档中设置它,但未设置标头.
屏幕有错误
尝试创建减速器并从操作中获取数据
但是在控制台中得到错误:reducer is not a function.....
我的减速机:
import { INCOME_LIST } from '../actionTypes'
import Immutable from 'immutable'
const initialUserState = {
list: []
}
const listReducer = function(state = initialUserState, action) {
switch(action.type) {
case 'INCOME_LIST':
return Object.assign({}, state, { list: action.data });
}
return state;
}
Run Code Online (Sandbox Code Playgroud)
我哪里有错?
我的行动:
import axios from 'axios'
import { INCOME_LIST } from '../actionTypes'
function receiveData(json) {
return{
type: INCOME_LIST,
data: json
}
};
export function IncomeList () {
return dispatch => {
return ( …Run Code Online (Sandbox Code Playgroud) 我有一个包含数组的对象.这是我浏览器中的图片:
例如,我只需要显示前两个数组.到目前为止,我已经尝试过了
var size = 2;
var sliced = joblist.slice(0, size);
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用,我收到以下消息
error:slice is not a function. it doesn't have a length
Run Code Online (Sandbox Code Playgroud)
有人能帮助我理解我做错了什么吗?