我试图将道具从子组件传递到父组件,但由于某种原因,我在js控制台中点击渲染的子组件后得到错误"TypeError:this.props.onClick不是函数".
基本上我要做的是管理一个类别列表,其中一个类别子组件将"selected"prop作为true,并且每次单击类别li时都会正确更新.
这是一个代码的jsfiddle:http://jsfiddle.net/kb3gN/8023/
我真的不觉得我已经掌握了如何有效地使用React.js的概念,所以任何帮助都表示赞赏!
最诚挚的问候和提前谢谢,
bnunamak
码:
var CategoryList = React.createClass({
getInitialState:function(){
return {
items:[
["cat1", false],
["cat2", true]
],
lastToggled:["cat2"]
}
},
//Function passed to child (changes items state)
handleClick:function(child){
var tempItems = this.state.items;
if(this.state.lastToggled[0] === child.props.name){
var index = this.getInd(this.state.tempItems, child.props.name);
tempItems[index][1] = !tempItems[index][1];
this.setState({items: tempItems});
}else{
var newIndex = this.getInd(this.state.tempItems, child.props.name);
tempItems[newIndex][1] = !tempItems[newIndex][1];
var oldIndex = this.getInd(this.state.tempItems, this.state.lastToggled[0]);
tempItems[oldIndex][1] = false;
this.setState({items: tempItems, lastToggled: tempItems[newIndex][0]});
}
},
//getInd not relevant to problem
getInd:function(arr, …Run Code Online (Sandbox Code Playgroud) 我开始学习libgdx和它的scene2d,但我的splashScreen遇到了麻烦.我的淡入淡出动作完美无缺,但Image没有被缩放(即使我在构造函数中添加了Scaling)......
我有一个从png 512x512加载的纹理splashTexture,其中真实图像是512x256,所以我创建了一个TextureRegion.所有这一切都在我的show方法中完成:
@Override
public void show() {
super.show(); //sets inputprocessor to stage
splashTexture = new Texture(SPLASHADR);
// set the linear texture filter to improve the stretching
splashTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
splashTextureRegion = new TextureRegion(splashTexture, 0, 0, 512, 256);
}
Run Code Online (Sandbox Code Playgroud)
然后在我的resize方法中出现以下内容:
@Override
public void resize(int width, int height) {
stage.clear();
Drawable splashTextureDrawable = new TextureRegionDrawable(
splashTextureRegion);
Image splashImg = new Image(splashTextureDrawable);
splashImg.getColor().a = 0f;
splashImg.addAction(Actions.sequence(Actions.fadeIn(0.5f),
Actions.delay(2f), Actions.fadeOut(0.5f)));
stage.addActor(splashImg);
}
Run Code Online (Sandbox Code Playgroud)
这些是SplashScreen类中的函数,它扩展了AbstractScreen类(实际上具有渲染功能):
@Override
public void render(float delta) {
stage.act(delta);
Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); …Run Code Online (Sandbox Code Playgroud) (对不起,长篇文章很抱歉)
我正在将我的应用程序从laravel 5.2升级到5.4,并且从今天早上开始一直停留在这个问题上。由于某种原因,我的查询选择了用雄辩的'whereDate'进行的即将发生的业务事件,但没有返回任何内容,尽管其他所有内容都表明它应该可以正常工作!
我有一个phpUnit测试,该测试不会通过以尝试将问题本地化。(请参见下文)
我有一个“ 商业 ”模式:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Business extends Model
{
protected $table = 'businesses';
..
public function businessEvents(){
return $this->hasMany('App\BusinessEvent', 'business_id');
}
Run Code Online (Sandbox Code Playgroud)
以及“ BusinessEvent ”模型:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class BusinessEvent extends Model
{
protected $table = 'business_events';
protected $fillable = ['business_id', ..., 'start_date', 'end_date'];
public function business(){
return $this->belongsTo('App\Business', 'business_id');
}
...
Run Code Online (Sandbox Code Playgroud)
我都在测试中制作了两个虚拟版本。虚拟“业务”可用于其他测试,但针对此测试用例,我引入了以下虚拟“ business_event”:
protected function createMockBusinessEventWithUpcomingDateTime($businessId){
$faker = Faker::create();
$businessEvent = BusinessEvent::create([
'business_id' => $businessId,
'name' => $faker->name, …Run Code Online (Sandbox Code Playgroud) 我有一个非常困惑的问题,即在文件的顶部,我调用了一个外部函数“ sessionTest”,该函数测试各种会话条件并返回正确的头字符串。这是必要的,因为我有两个不同的标题:一个用于登录的用户,一个用于非用户/注销的用户。
我的问题在以下代码中:
<?php include './session.php';
include './db.php';
$con = genCon();
if(isset($_SESSION['logged'])){
echo "Logged: ".$_SESSION['logged'];
}
$headerstring = sessionTest($con); ?>
...Rest of Page...
Run Code Online (Sandbox Code Playgroud)
由于某种原因,isset($ _ SESSION ['logged'])在这里返回false,但在sessionTest中为true:
function sessionTest($con){
session_start();
$fingerprint = md5($_SERVER['HTTP_USER_AGENT'].session_id());
if(isset($_SESSION['user']) && isset($_SESSION['logged']) && $_SESSION['logged']==TRUE){
$dbFingerprint = qGetUserFingerprint($_SESSION['user'],$con);
$fpMatch = ($dbFingerprint == $fingerprint);
//LEAVING OUT NON RELEVANT CODE
$headerstring = './lheader.html';
}else{
$headerstring = './header.html';
}
return $headerstring;
}
Run Code Online (Sandbox Code Playgroud)
标头字符串设置为lheader.html,因此isset($ _ SESSION ['logged'])在此处返回true。有谁知道为什么?
提前致谢!