我正在尝试将反应连接到我的应用程序中.它是一个使用rails-rails的rails应用程序(虽然我不认为这是问题的一部分).我目前正在使用一个非常简单的1组件设置:
// react_admin.js.jsx
/** @jsx React.DOM */
var CommentBox = React.createClass({
render: function() {
return (
<div className="commentBox">
Hello, world! I am a CommentBox.
</div>
);
}
});
React.render(
<CommentBox />,
document.getElementById('content')
);
Run Code Online (Sandbox Code Playgroud)
我的html文件包含:
<body>
<div id="content"></div>
<script src="/assets/react.js?body=1"></script>
<script src="/assets/react_admin.js?body=1"></script>
</body>
Run Code Online (Sandbox Code Playgroud)
我可以看到rails-react将我的react_admin.js.jsx转换为react_admin.js,如下所示:
/** @jsx React.DOM */
var CommentBox = React.createClass({displayName: 'CommentBox',
render: function() {
return (
React.DOM.div({className: "commentBox"},
"Hello, world! I am a CommentBox."
)
);
}
});
React.render(
CommentBox(null),
document.getElementById('content')
);
Run Code Online (Sandbox Code Playgroud)
然而,chrome在Render.react()调用中引发了''Uncaught TypeError:undefined不是函数',它在"("和"CommentBox(null)"之间显示)
有人能告诉我我做错了什么吗?
看起来Chainsaw的开发已经在4年前停止了(2006-03-02的最后开发版本)......
任何人都知道提供相同功能的替换工具,但有更新的版本?
当我注意到这件事时,我正在使用一些代码在Node.js中玩:
> 'hello world'.padEnd(20);
'hello world '
> 'hello world'.padEnd(20, _);
'hello worldhello wor'
Run Code Online (Sandbox Code Playgroud)
下划线符号在这里做什么?
> _
'hello worldhello wor'
Run Code Online (Sandbox Code Playgroud) 在过去的几个小时里,我一直试图绕过这个问题,但无法理解.我想我还是要习惯函数式编程风格;)
我编写了一个递归函数,遍历目录结构并对某些文件执行操作.此函数使用异步IO方法.现在我想在整个遍历完成时执行一些操作.
如何在执行所有parse调用但仍使用异步IO功能后确保执行此操作?
var fs = require('fs'),
path = require('path');
function parse(dir) {
fs.readdir(dir, function (err, files) {
if (err) {
console.error(err);
} else {
// f = filename, p = path
var each = function (f, p) {
return function (err, stats) {
if (err) {
console.error(err);
} else {
if (stats.isDirectory()) {
parse(p);
} else if (stats.isFile()) {
// do some stuff
}
}
};
};
var i;
for (i = 0; i < files.length; i++) …Run Code Online (Sandbox Code Playgroud) 我在TypeScript中输入了一个拼写错误,这是在代码审查期间被选中的.
我用someArray.indexOf[someObject]而不是someArray.indexOf(someObject).
我希望IDE /编译器出错.相反,没有引发错误,结果只是未定义.
有谁能解释一下?
我在 CodeWars 上找到了一个任务,我设法解决了它,但是,提交后说:
执行超时:(12000 毫秒)
当我尝试测试该函数是否通过时,但我猜它太慢了。在你谴责我没有自己找到答案之前。我并不真正关心将其作为回复提交,但我不知道如何使其更快,这就是我在这里的原因。这是函数:
const ls = [0, 1, 3, 6, 10]
const partsSums = (ls) => {
const sum = []
for(let i = 0, len = ls.length; i < len + 1; i++) {
let result = ls.slice(i).reduce( (accumulator, currentValue) => accumulator + currentValue, 0)
sum.push(result)
}
return sum
}
Run Code Online (Sandbox Code Playgroud)
以下是说明:
让我们考虑这个例子(以通用格式编写的数组):
Run Code Online (Sandbox Code Playgroud)ls = [0, 1, 3, 6, 10]其以下部分:
Run Code Online (Sandbox Code Playgroud)ls = [0, 1, 3, 6, 10] ls = [1, 3, 6, 10] ls = [3, …
我做了一个iphone健身应用程序.我无法解决的问题是,当应用程序运行时,iphone进入睡眠模式,因此加速计和声音关闭.我不想发生这种事.
无论如何我可以避免这种情况发生吗?如果不是这样,至少我可以增加我的iPhone进入睡眠模式的时间.
关心Zeeshan
如果我有这样的事情:
var blah = function() { };
Run Code Online (Sandbox Code Playgroud)
然后在代码中使用了blah,JSLint提示说删除空块是什么?
我个人喜欢三元运算符,并且在我看来,他们使复杂的表达式很容易消化.拿这个:
word = (res.distance === 0) ? 'a'
: (res.distance === 1 && res.difference > 3) ? 'b'
: (res.distance === 2 && res.difference > 5 && String(res.key).length > 5) ? 'c'
: 'd';
Run Code Online (Sandbox Code Playgroud)
但是在我们项目的ESLINT规则中,嵌套的三元运算符是被禁止的,所以我必须摆脱上述情况.
我试图找出这种方法的替代方案.我真的不想把它变成一个巨大的if/else语句,但不知道是否还有其他选择.
提出这样的要求:
return fetch(
'http://localhost:8000/login',
{ method: 'POST',
headers: new Headers(
{"Content-Type": "application/json",
"Accept":"application/json"}
),
body: JSON.stringify(
{'name': 'Tom', 'password': 'Soyer'}
)
}
).then( response => { console.log(response);})
.catch(err => console.log(err))
Run Code Online (Sandbox Code Playgroud)
请求使用OPTIONS方法运行而不是POST.仅在添加模式时:'no-cors'请求变为POST:
return fetch(
'http://localhost:8000/login',
{ method: 'POST',
mode: 'no-cors',
headers: new Headers(
{"Content-Type": "application/json",
"Accept":"application/json"}
),
body: JSON.stringify(
{'name': 'Tom', 'password': 'Soyer'}
)
}
).then( response => { console.log(response);})
.catch(err => console.log(err))
Run Code Online (Sandbox Code Playgroud)
但响应不好(即使网络响应状态为200):{type:"opaque",url:"",status:0,ok:false,statusText:""...}我想是因为
Content-Type标头唯一允许的值是:application/x-www-form-urlencoded multipart/form-data text/plain
这里描述https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
是否有任何方式可以使用fetch生成POST json数据?
javascript ×7
node.js ×2
arrays ×1
asynchronous ×1
cors ×1
eslint ×1
fetch-api ×1
function ×1
iphone ×1
jslint ×1
log4j ×1
logging ×1
methods ×1
objective-c ×1
properties ×1
react-jsx ×1
react-rails ×1
reactjs ×1
sleep-mode ×1
sum ×1
typescript ×1
xcode ×1