我有两个抽象的状态parent,并parent.child和一个可激活的状态parent.child.grand.
我想parent将承诺解决之前parent.child.grand得到它做出决议执行.为什么?因为它来自于从决心Ajax请求的特定数据parent在需要parent.grand.child.
这是一个要点
是否可以在不使用控制器的情况下顺序将父级的承诺链接到子状态?
(parent解决开始 - >完成ajax请求 - >解析promise - > parent.child.grand解决启动 - >完成ajax请求 - >解析promise
我使用browserify和watchify,并想require()比默认扩展名的其他文件.js,并.json没有指定扩展名,比如:
// Not ideal (tedious)
var Carousel = require('./components/Carousel/Carousel.jsx')
// Ideal
var Carousel = require('./components/Carousel/Carousel')
Run Code Online (Sandbox Code Playgroud)
我曾尝试--extension=EXTENSION为在指定browserify文档:
"scripts": {
"build": "browserify ./src/App.js --transform [ reactify --es6 ] > dist/script.js -v -d --extension=jsx",
"watch": "watchify ./src/App.js --transform [ reactify --es6 ] -o dist/script.js -v -d --extension=jsx"
},
Run Code Online (Sandbox Code Playgroud)
但是我没有看到任何变化.这可能吗?这样做的正确方法是什么?
使用RefluxJS初始化数据(异步)的正确方法是什么?是否有类似于AngularJS的解决方案,或者Flux实现与此无关(路由器应该处理这种可靠性)?
我正在使用Laravel 5.1.我正在尝试使用Blade指令(@extend)和我的自定义Blade指令.
Blade::directive('base', function() use ($theme) {
return "@extends($theme)"
});
Run Code Online (Sandbox Code Playgroud)
但是,上面的代码只是字面上显示内容(@extends($theme))
我有一个 div (固定),其作用类似于弹出窗口:
<body>
<div class="popup-container">
<div class="popup-item">
Yolowing
</div>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
此 css 允许容器水平居中(宽度为 100% 使其后面的所有内容都不可点击;因此,我将其设置为 1px):
.popup-container {
position: fixed;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
width: 1px;
z-index: 9999;
}
.popup-item {
display: block;
min-width: 20px;
padding: 25px 50px;
background-color: yellow;
}
Run Code Online (Sandbox Code Playgroud)
.popup-item但是,由于父元素.popup-container小于其子元素,我无法居中。如何居中.popup-item同时仍然能够单击它(pointer-events: none完全禁用它)?
我使用Jest来测试我的React组件.但是,我不知道(或者没有看到任何东西)如何测试将方法传递给子组件的组件(作为prop).举例来说,我有:Form,MemberList,Member,FormButton.代码中与此类似的东西:
形成:
<MemberList members={this.state.members} remove={this.remove} add={this.add} />
<FormButton data={this.state.members} />
Run Code Online (Sandbox Code Playgroud)
会员:
<span onClick={this.add}> <!-- add button --> </span>
{this.props.members.map(function(member, index) {
<Member key={index} data={member} remove={this.props.remove} />
})}
Run Code Online (Sandbox Code Playgroud)
会员:
// some input like name and so, and a remove itself button.
Run Code Online (Sandbox Code Playgroud)
FormButton:
var submit = function() {
this.setState({ loading: true });
// xhr
}
<button type="button" onClick={submit} disabled={this.state.loading}>Submit</button>
Run Code Online (Sandbox Code Playgroud)
我是否以正确的心态思考?补充一点,那里有实际的例子吗?
*在尝试React和Jest之前,我从未测试过.
我一直想用 BabelJS 来做这件事,但是我不确定 Babel 或规范目前是否支持它。
鉴于Outer.js:
export default function() { }
Run Code Online (Sandbox Code Playgroud)
下面的例子不起作用。
export Outer from './Outer'
Run Code Online (Sandbox Code Playgroud)
使用 CommonJS 模块,这可以很容易地写成
exports.x = require('./x');
Run Code Online (Sandbox Code Playgroud) 有没有办法触发标签error事件img来测试我的onError回调?例如,给定这个组件,
import React from 'react';
/**
* Self removing <img> when the `src` or image
* does not load or is unavailable.
*
* Usage: (tip: it's how you use the <img> tag, basically)
* <Img src={} alt={} ../..>
*/
var Img = React.createClass({
/**
* Force update so `refs` will be available
*/
componentDidMount() {
this.forceUpdate();
},
render() {
// Omit any passed `onError` prop so that
// it is never overridden by …Run Code Online (Sandbox Code Playgroud) 我正在使用名为seven_ora的2个连接的MSSQL(用户模型的表位于其中)和sho(字符模型的表所在的连接).
用户拥有多个字符,而一个字符属于用户.
当我尝试:
Character::whereHas('User', function($q) { $q->where('gm', 1); });
Run Code Online (Sandbox Code Playgroud)
它似乎使用与Character相同的连接.似乎whereHas中的闭包是Query\Builder?我期望whereHas使用它所指的任何模型的相应集合连接.
有没有办法在我的whereHas闭包上使用不同的连接?
Characters.php(模型)
class Character extends Base {
/**
* Connection used by the model
*
* @var string
*/
protected $connection = 'sho';
/**
* Table used by the model
*
* @var string
*/
protected $table = 'tblgs_avatar';
/**
* Fields fillable by the model
*
* @var array
*/
protected $guarded = array('*');
/**
* Checks whether the model uses timestamps
*
* @var boolean
*/
public $timestamps …Run Code Online (Sandbox Code Playgroud) 有没有办法从闭包外的闭包访问变量?例如,我想$wallet在闭包之外访问:
public function generate()
{
$this->ssh->run([
'~/Web/gatewayd/gateway generate_wallet'
], function($line) use ($fn)
{
$wallet = data $line.PHP_EOL;
});
return json_decode($wallet);
}
Run Code Online (Sandbox Code Playgroud)
我尝试了这个解决方案,但我觉得这既不奏效,也不是一个好习惯:
public function generate()
{
$wallet = null;
$this->ssh->run([
'~/Web/gatewayd/gateway generate_wallet'
], function($line) use ($wallet)
{
$wallet = $line;
});
return json_decode($wallet);
}
Run Code Online (Sandbox Code Playgroud) javascript ×7
reactjs ×4
angularjs ×2
jestjs ×2
laravel ×2
angular-ui ×1
blade ×1
browserify ×1
closures ×1
css ×1
ecmascript-6 ×1
eloquent ×1
flux ×1
html ×1
laravel-5 ×1
php ×1
react-jsx ×1
refluxjs ×1
scope ×1
testing ×1