我有2个减速器组合在Root Reducer中,并在商店中使用.第一个reducer'MisscksReducer'应该返回一个对象,第二个'FavoritesReducer'应该返回一个数组.
当我在连接中创建容器组件和mapStateToProps方法时,由于某种原因,存储的返回状态是一个对象,其中包含2个包含数据的reducer对象,而不仅仅是包含重叠数据的对象,如预期的那样.
function mapStateToProps(state) {
debugger:
console.dir(state)
//state shows as an object with 2 properties, AllTracksReducer and FavoritesReducer.
return {
data: state.AllTracksReducer.data,
isLoading: state.AllTracksReducer.isLoading
}
}
export default connect(mapStateToProps)(AllTracksContainer);
Run Code Online (Sandbox Code Playgroud)
所以,在mapStateToProps中,要获得正确的状态属性,我必须说state.AllTracksReducer.data ...但是我期待数据直接在状态对象上可用?
我该怎么写这个函数?任何例子都赞赏
function isPointBetweenPoints(currPoint, point1, point2):Boolean {
var currX = currPoint.x;
var currY = currPoint.y;
var p1X = point1.x;
var p1y = point1.y;
var p2X = point2.x;
var p2y = point2.y;
//here I'm stuck
}
Run Code Online (Sandbox Code Playgroud) 我将如何在JS中创建一个类似树的数据结构,在那里,我可以访问诸如父节点的引用,基于id的节点查找,访问子节点的长度(数量),基于索引的查找等等?
这基本上就是我想象的API:
var rootNode = DataStructure.getRoot();
var child1 = rootNode.addNode('child1'); //added a node with id 'child1'
child1.addNode('innerChild1');
child1.addNode('innerChild2');
rootNode.getChildById('child1') //should be same node as var child1
rootNode.getAtIndex(0) //should be same node as var child1
child1.parent() //should be rootNode
child1.getAtIndex(0) // should be node with id 'innerChild1'
child1.getAtIndex(1) // should be node with id 'innerChild2'
child1.length() //should be 2
Run Code Online (Sandbox Code Playgroud)
等等..
我理解它的一个广泛的问题,但我想知道是否有人可以推荐一种方法来处理这个和/或任何可能已经这样做的库?我应该动态创建XML并使用其本机方法吗?那会是最快的吗?
我有一个基于http://moduscreate.com/code-splitting-for-react-router-with-es6-imports/文章的应用程序.我添加了一些子路由,现在我的路由器配置是这样的:
function errorLoading(err) {
console.error('Dynamic page loading failed', err);
}
function loadRoute(cb) {
console.log('load route called');
return (module) => cb(null, module.default);
}
const obj = {
component: App,
childRoutes: [
{
path: '/',
getComponent(location, cb) {
System.import('pages/Home')
.then(loadRoute(cb))
.catch(errorLoading);
}
},
{
path: '/gsgs',
getComponent(location, cb) {
System.import('pages/Gsgs')
.then(loadRoute(cb))
.catch(errorLoading);
},
childRoutes: [
{
path: 'go',
getComponent(location, cb) {
System.import('pages/Gsgs/Home.js')
.then(loadRoute(cb))
.catch(errorLoading);
},
}
]
},
{
path: '/about',
getComponent(location, cb) {
System.import('pages/About')
.then(loadRoute(cb))
.catch(errorLoading);
}
},
] …Run Code Online (Sandbox Code Playgroud) 如果我要使用fps,使用一个较大的画布并不断重绘或者使用一堆小画布并且不经常重绘但使用css3来制作这样的动画会更快吗?
<canvas id="1" width="60px" height="60px"></canvas>
<canvas id="2" width="60px" height="60px"></canvas>
<canvas id="3" width="60px" height="60px"></canvas>
<canvas id="4" width="60px" height="60px"></canvas>
Run Code Online (Sandbox Code Playgroud) 我想根据用户的登录信息从PHP提供信息到iPhone应用程序.我可以使用会话/ cookie路由来验证来自应用程序的请求,还是必须使用某种令牌身份验证?基本上,如果我从iPhone应用程序调用服务,php可以留下cookie(与浏览器相同)吗?
根据谷歌抓取,AJAX和HTML5 ,谷歌可以抓取使用历史API的动态网页,但它表示谷歌不会在页面上执行任何JavaScript.对我而言,这意味着不会制作ajax请求和dom构建,因此google将无法索引加载的页面内容.有人可以详细说明吗?
我有一个带有可观察数组的视图模型.它填充了一些json:
this.socialTiles = ko.observableArray([]);
ko.computed(function () {
jQuery.getJSON( this.apiURL+"&callback=?", function (data) {
var theData = data.entries;
tilesModel.socialTiles(theData);
console.dir(theData);
});
}, tilesModel);
Run Code Online (Sandbox Code Playgroud)
对于模型中的每个项目,我使用模板构建一个li:
<ul id="tiles-ul" data-bind="template: {name:'twitter_template', foreach:socialTiles}">
<script type="text/html" id="twitter_template">
<li class="social-tile box-shadow">
<div class="header">
<div class="header-img">
<img data-bind="attr: { src: actor.avatar}">
</div>
<div class="name_and_time">
<span class="full-name" data-bind="text: actor.title"></span>
<span class="twitter-name" data-bind="text: actor.id"></span>
<span class="how-long-ago" > 5 minutes ago </span>
</div>
</div>
<div class="message-content" data-bind="html: object.content">
</div>
<div class="footer">
<div class="social-icon-twitter">
</div>
</div>
<span data-bind="text: $index"></span>
</li>
</script>
Run Code Online (Sandbox Code Playgroud)
id喜欢将元素的文本数据绑定为函数的结果,其中来自模型的当前数据用作参数.例:
actor.id是一个包含用户的twitter …
比方说,我有一个div是有translateX和translateY值动态增加.
<div class="object child0"
style="-webkit-transform: translateX(873.5px) translateY(256px);
width: 50px; height: 50px;">
Run Code Online (Sandbox Code Playgroud)
我想添加rotateY(20deg)到当前的转换,但通过element.style.webkitTransform = "rotateX(20deg)"丢失其他值来应用它
.
有没有办法添加rotateY而不丢失translateX和translateY转换?
我想看看iPhone应用程序发出的请求/响应.我主要从事网络应用程序,我可以使用firebug/fiddler来查看它们.但是,如果我在无线网络上运行它,我如何才能看到iOS应用的传入/传出流量?
我正在使用Pixi.js并尝试将动画帧保存到图像中.canvas.toDataUrl应该可以工作,但我得到的只是一个黑色矩形.在这里查看实例
我用来提取图像数据和设置图像的代码是:
var canvas = $('canvas')[0];
var context = canvas.getContext('2d');
$('button').click(function() {
var data = renderer.view.toDataURL("image/png", 1);
//tried var data = canvas.toDataURL();
$('img').attr('src', data);
})
Run Code Online (Sandbox Code Playgroud) 这是表模式:
CREATE TABLE `USERS` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`email` varchar(30) DEFAULT '',
`first_name` varchar(15) DEFAULT '',
`last_name` varchar(15) DEFAULT '',
`password` varchar(15) DEFAULT '',
`gender` int(1) DEFAULT '-1',
PRIMARY KEY (`id`)
)
Run Code Online (Sandbox Code Playgroud)
在PHP中:
$sql = 'INSERT INTO Users (email, first_Name, last_Name, password, gender ) VALUES ("'.$email.'", "'.$first_name.'", "'.$last_name.'", "'.$password.'", '.$gender.')';
try {
$db = getConnection();
$stmt = $db->prepare($sql);
$stmt->execute();
//$user = $stmt->fetchObject();
echo 'last id was '.mysql_insert_id();
$db = null;
} catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() …Run Code Online (Sandbox Code Playgroud) '假设我有一个对象
var obj = {
apples: 2,
grapes: 1,
oranges:2,
carrots:2,
potatoes: 4
}
Run Code Online (Sandbox Code Playgroud)
我将如何编写一个快速执行的函数来返回按其值分组的键?
return {
"2": ['apples', 'oranges', 'carrots'],
"4" : ['potatoes'],
"1" : ['grapes']
}
Run Code Online (Sandbox Code Playgroud) javascript ×8
jquery ×3
css3 ×2
html5 ×2
php ×2
algorithm ×1
arrays ×1
canvas ×1
debugging ×1
geometry ×1
history.js ×1
html5-canvas ×1
http ×1
insert ×1
ios ×1
iphone ×1
json ×1
knockout.js ×1
mysql ×1
oop ×1
pixi.js ×1
react-redux ×1
react-router ×1
reactjs ×1
redux ×1
web-services ×1
webgl ×1
webpack ×1