据我所知,React教程和文档毫不含糊地警告说,状态不应该直接变异,并且一切都应该通过setState.
我想明白为什么,确切地说,我不能直接改变状态,然后(在同一个函数中)调用this.setState({})只是为了触发render.
例如:以下代码似乎工作得很好:
const React = require('react');
const App = React.createClass({
getInitialState: function() {
return {
some: {
rather: {
deeply: {
embedded: {
stuff: 1
}}}}};
},
updateCounter: function () {
this.state.some.rather.deeply.embedded.stuff++;
this.setState({}); // just to trigger the render ...
},
render: function() {
return (
<div>
Counter value: {this.state.some.rather.deeply.embedded.stuff}
<br></br>
<button onClick={this.updateCounter}>inc</button>
</div>
);
}
});
export default App;
Run Code Online (Sandbox Code Playgroud)
我完全遵循以下约定,但我想进一步了解ReactJS如何实际运行,哪些可能出错或者是否与上述代码不是最佳的.
this.setState文档下的注释基本上确定了两个陷阱:
this.setState它可能会替换(覆盖?)你所做的突变.我不知道在上面的代码中会发生这种情况.setState …如何将以下Yii代码实现到Yii2:
<?php
echo $form->dropDownList($model,
'project',
$model->getProjectOptions(),
array('empty' => 'Empty string')
);
?>
Run Code Online (Sandbox Code Playgroud) 我有JS的动态网页.有一个<textarea>和一个发送按钮,但没有<form>标签.如何在按下Enter时按下" 提交"按钮并<textarea>清除"清除" ?<textarea>
我在CPanel上创建了一个FTP帐户.我也尝试在JetBrains PhpStorm上配置FTP,但我无法建立连接.
我制作了如下FTP帐户;
FTP Username: ****@*********.org
FTP server: ****.****.org
FTP & explicit FTPS port: 21
Run Code Online (Sandbox Code Playgroud)
我需要有关如何public_html/从JetBrains PhpStorm 连接到文件夹然后同步文件的建议.
我按照文档将常量放在lib/constants.js文件中.
问题:如何在我的客户端html和js文件中访问这些常量?
是否有人在使用 node js ioredis 包连接到独立 redis 服务器时遇到以下错误?
以下是错误堆栈跟踪:
2018-08-16T10:52:18.351869060Z [ioredis] Unhandled error event: Error: connect ETIMEDOUT
2018-08-16T10:52:07.449457296Z at Timer.listOnTimeout (timers.js:207:5)
2018-08-16T10:52:07.449448499Z at tryOnTimeout (timers.js:237:5)
2018-08-16T10:52:07.449439722Z at ontimeout (timers.js:365:14)
2018-08-16T10:52:07.449430834Z at Socket._onTimeout (net.js:339:8)
2018-08-16T10:52:07.449421915Z at Socket.emit (events.js:185:7)
2018-08-16T10:52:07.449413002Z at emitNone (events.js:86:13)
2018-08-16T10:52:07.449403458Z at Socket.g (events.js:291:16)
Run Code Online (Sandbox Code Playgroud)
这是在节点 js 中仅实例化独立 Redis 对象时发生的。下面是我正在使用的代码,
var publisher = new redis(redisPort, redisHost);
Run Code Online (Sandbox Code Playgroud)
任何解决方案将不胜感激。
我是Yii2的新手.谁能告诉我如何用mongodb配置YII2以及如何在YII2和mongodb之间建立连接?我试图从git hub下载mongodb软件包并尝试运行以下命令
php composer.phar require --prefer-dist yiisoft/yii2-mongodb "*"
Run Code Online (Sandbox Code Playgroud)
在我已安装Yii2的根文件夹内的命令提示符下,但是我收到以下错误
Your requirements could not be resolved to an installable set of packages.
Problem 1
- yiisoft/yii2 2.0.0 requires bower-asset/jquery 2.1.*@stable | 1.11.*@stable -> no matching package found.
- yiisoft/yii2 2.0.0 requires bower-asset/jquery 2.1.*@stable | 1.11.*@stable -> no matching package found.
- Installation request for yiisoft/yii2 == 2.0.0.0 -> satisfiable by yiisoft/yii2[2.0.0].
Run Code Online (Sandbox Code Playgroud) 我是MongoDB 3.2 的新手,
考虑下面的例子,
{ "_id" : "2tLX8ALYfRvbgiurZ", "service" : "GSTR 1" }
{ "_id" : "2tLX8ALYfRvbgiurZ", "service" : "GSTR 2" }
{ "_id" : "2tLX8ALYfRvbgiurZ", "service" : "GSTR 3" }
Run Code Online (Sandbox Code Playgroud)
如何使用Group By _id并创建单个字段并连接所有文档字段,以下是预期的输出,
{ "_id" : "2tLX8ALYfRvbgiurZ", "service" : "GSTR 1, GSTR 2, GSTR 3" }
Run Code Online (Sandbox Code Playgroud)
我在下面使用但它给出了数组,
db.getCollection('Clients').aggregate(
[
{
$group : {
_id : "$_id",
services : "$services"
}
}
]
).map( doc =>
Object.assign(
doc,
{ "services": doc.services.join(",") }
)
);
Run Code Online (Sandbox Code Playgroud)
它给出输出为
[{ …Run Code Online (Sandbox Code Playgroud) 只是为了试用,我使用 Chocolatey 安装了 Meteor 1.6。
当我运行命令“choco installmeteor”时,过了一会儿,我收到以下错误
Downloading meteor 64 bit
from 'https://packages.meteor.com/bootstrap-link?arch=os.windows.x86_64'
Progress: 48% - Saving 83.27 MB of 171.74 MB C
hocolatey timed out waiting for the command to finish. The timeout
specified (or the default value) was '2700' seconds. Perhaps try a
higher `--execution-timeout`? See `choco -h` for details.
The install of meteor was NOT successful.
Error while running 'C:\ProgramData\chocolatey\lib\meteor\tools\chocolateyinstal
l.ps1'.
See log for details.
Chocolatey installed 1/2 packages. 1 packages failed.
See the log for details …Run Code Online (Sandbox Code Playgroud) 我在Node JS 10.9中将HAPI JS与HTTP / 2一起使用。当我使用此示例启动服务器时,
const fs = require('fs')
const Hapi = require('hapi')
const http2 = require('http2')
const server = new Hapi.Server()
server.connection({
listener: http2.createServer(),
host: 'localhost',
port: 3000
})
server.route({
method: 'GET',
path:'/hello',
handler: function (request, reply) {
return reply('Hello, World!')
}
})
server.start((err) => {
if (err) console.error(err)
console.log(`Started ${server.connections.length} connections`)
})
Run Code Online (Sandbox Code Playgroud)
我在控制台上收到此警告
(node:16600) ExperimentalWarning: The http2 module is an experimental API.
Run Code Online (Sandbox Code Playgroud)
我无法在互联网上找到有关是否可以在生产模式下使用它的相关解释?可以在生产模式下将HTTP / 2与此类警告一起使用吗?
此链接纯粹指定libuv提供一个线程池,可用于运行用户代码并在循环线程中获得通知。它的默认大小为 4,但可以在启动时通过将UV_THREADPOOL_SIZE环境变量设置为任何值来更改它。(绝对最大值为 128)。
因此,在 中package.json,我将scripts字段设置如下(注意:我使用的是 Windows 7、Node JS 8.11.3、nodemon、express 4.16),
代码片段来自 package.json
.
.
.
"scripts": {
"start": "SET UV_THREADPOOL_SIZE = 120 && node index.js",
},
.
.
.
Run Code Online (Sandbox Code Playgroud)
代码 index.js
var express = require('express');
var app = express();
var server = app.listen(3000, function(){
console.log('LIBUV Threads: ', process.env.UV_THREADPOOL_SIZE); // this returns 'undefined'
});
Run Code Online (Sandbox Code Playgroud)
我如何确保设置了线程池大小?我想在index.js上面打印出来。
我正在使用下面的代码。
[
'attribute' => 'Application',
'format' => 'html',
'value' => function ($dataProvider) {
$student_username = $dataProvider->student_username;
return Html::a('Print', Url::toRoute(['/coordinatorpanel/print-form', 'student_username' => $student_username]),
['target' => '_blank', 'class' => 'btn btn-success center-block']);
},
]
Run Code Online (Sandbox Code Playgroud)
HTML输出:
<a class="btn btn-success center-block" href="/nse/frontend/web/index.php?r=coordinatorpanel%2Fprint-form&student_username=COR39690113" target="_blank">
Run Code Online (Sandbox Code Playgroud)
但是,当我单击链接时,没有导航到新选项卡,该请求在同一选项卡中处理。我在“ Mozilla”和“ Chrome”上都尝试过。
任何帮助将被深深地提醒:)
我正在尝试找到一种更好的方法来连接JavaScript ES6中的字符串。以下是当前代码段。
方法1:
function concat(...strings){
return ''.concat(...strings);
}
Run Code Online (Sandbox Code Playgroud)
方法2:
function concat(...strings){
return strings.join('');
}
Run Code Online (Sandbox Code Playgroud)
例:
concat("Hey", "There", "How", "Are", "You"); // output is "HeyThereHowAreYou"
Run Code Online (Sandbox Code Playgroud)
我不确定这些方法的性能,因为参数数量可能会增加。任何评论将不胜感激,这可能是最好的,或者任何其他方法都可以提供帮助。