我是一个javascript/redux/react初学者用redux,react-redux和react做一个小应用程序.出于某种原因,当使用mapDispatchToProps函数与connect(react-redux binding)串联时,我收到一个TypeError,指示当我尝试执行生成的prop时,dispatch不是函数.当我将调度调用为prop时(参见提供的代码中的setAddr函数)它可以工作.
我很好奇为什么会这样,在redux文档中的示例TODO应用程序中,mapDispatchToProps方法的设置方式相同.当我在函数内部调试console.log(dispatch)时,它表示dispatch是type对象.我可以继续以这种方式使用调度,但在我继续使用redux之前,我会更好地了解为什么会发生这种情况.我正在使用带有babel-loaders的webpack进行编译.
我的代码:
import React, { PropTypes, Component } from 'react';
import { connect } from 'react-redux';
import { setAddresses } from '../actions.js';
import GeoCode from './geoCode.js';
import FlatButton from 'material-ui/lib/flat-button';
const Start = React.createClass({
propTypes: {
onSubmit: PropTypes.func.isRequired
},
setAddr: function(){
this.props.dispatch(
setAddresses({
pickup: this.refs.pickup.state.address,
dropoff: this.refs.dropoff.state.address
})
)
},
render: function() {
return (
<div>
<div className="row">
<div className="col-xs-6">
<GeoCode ref='pickup' />
</div>
<div className="col-xs-6">
<GeoCode ref='dropoff' />
</div>
</div>
<div className="row">
<div className="col-xs-6">
<FlatButton
label='Does Not …Run Code Online (Sandbox Code Playgroud) 简单的问题,我有一个我正在抓住的元素.getElementById ().如何检查是否有孩子?
function Shape() {
this.name = "Generic";
this.draw = function() {
return "Drawing " + this.name + " Shape";
};
}
function welcomeMessage()
{
var shape1 = new Shape();
//alert(shape1.draw());
alert(shape1.hasOwnProperty(name)); //this is returning false
}
Run Code Online (Sandbox Code Playgroud)
.welcomeMessage呼吁这个body.onload事件.
我期望shape1.hasOwnProperty(name)返回true,但它返回false.
什么是正确的行为?
WebWorker可以访问localStorage吗?
如果不是为什么不呢?从安全角度来看,这有问题吗?
我开始使用过渡来"现代化"网站的感觉.到目前为止,:hover转型运作良好.现在我想知道是否有可能基于其他事情触发转换,例如当一个类发生变化时.
这是相关的CSS:
#myelem {
opacity: 0;
display: none;
transition: opacity 0.4s ease-in, display 0.4s step-end;
-ms-transition: opacity 0.4s ease-in, display 0.4s step-end;
-moz-transition: opacity 0.4s ease-in, display 0.4s step-end;
-webkit-transition: opacity 0.4s ease-in, display 0.4s step-end;
}
#myelem.show {
display: block;
opacity: 1;
transition: opacity 0.4s ease-out, display 0.4s step-start;
-ms-transition: opacity 0.4s ease-out, display 0.4s step-start;
-moz-transition: opacity 0.4s ease-out, display 0.4s step-start;
-webkit-transition: opacity 0.4s ease-out, display 0.4s step-start;
}
Run Code Online (Sandbox Code Playgroud)
触发更改的JavaScript是:
document.getElementById('myelem').className = "show";
Run Code Online (Sandbox Code Playgroud)
但过渡似乎并没有发生 - …
我正在使用redux而且我不确定如何组织我的组件,我认为最好将它们保存在文件夹中,主要组件的名称作为文件夹的名称和内部的所有内部组件:
components
Common/ things like links, header titles, etc
Form/ buttons, inputs, etc
Player/ all small components forming the player
index.js this one is the top layout component
playBtn.js
artistName.js
songName.js
Episode/ another component
然后,在容器文件夹中,我每页只有一个容器,这是我实际连接到Redux的唯一容器:
containers/ HomePageApp.js EpisodePageApp.js ...
然后每个顶部组件的操作是一个,而不是每页一个,所以在我连接到Redux的页面容器中,我传递了该页面中使用的组件的所有操作.例如:
actions/ Player.js Episode.js ...
我这样做了吗?我没有找到关于谷歌搜索的很多信息,我发现我认为它们仅限于小项目.
谢谢!
他们似乎都做同样的事情.我只是担心一个人使用不同时区的时区.
让我们谈谈每秒都有setInterval方法的JavaScript代码2.
我还有一个onblur控件的动画事件.
在onblur发生(+动画)的情况下,我可能会得到这个setInterval功能.
所以我的问题是:
异步编程是否意味着多线程?(以任何方式?)
我知道Javascript不是一种多线程语言.
所以...?
我正在尝试设计一个通知组件,其中通知将在某些场合出现(如连接问题,成功修改等).
我需要在几秒钟后消失通知,因此我触发状态更改以从通知setTimeout内部删除Redux状态的通知componentDidMount.
我可以看到状态确实发生了变化,但React-Redux没有重新渲染父组件,因此通知仍然出现在DOM上.
这是我的Redux减速机:
const initialState = {
notifications: []
}
export default function (state = initialState, action) {
switch(action.type) {
case CLEAR_SINGLE_NOTIFICATION:
return Object.assign ({}, state, {
notifications: deleteSingleNotification(state.notifications, action.payload)
})
case CLEAR_ALL_NOTIFICATIONS:
return Object.assign ({}, state, {
notifications: []
})
default:
return state
}
}
function deleteSingleNotification (notifications, notificationId) {
notifications.some (function (notification, index) {
return (notifications [index] ['id'] === notificationId) ?
!!(notifications.splice(index, 1)) :
false;
})
return notifications;
}
Run Code Online (Sandbox Code Playgroud)
和我的React组件(Main和Notification …
我正在尝试仅使用HTML/CSS创建矩阵效果,我发现的方法是应用实心边框,现在擦除顶部和底部的一些部分,有人知道如何才能使用CSS创建此效果(如果这是可能的) ?
有一张图片可以更好地解释我的目标:

javascript ×7
reactjs ×3
redux ×3
css ×2
html5 ×2
react-redux ×2
.net ×1
asynchronous ×1
css3 ×1
dom ×1
html ×1
jquery ×1
reactjs-flux ×1
web-worker ×1