我正在尝试制作一个漂亮的ApiWrapper组件来填充各种子组件中的数据.从我读过的所有内容来看,这应该有效:https://jsfiddle.net/vinniejames/m1mesp6z/1/
class ApiWrapper extends React.Component {
constructor(props) {
super(props);
this.state = {
response: {
"title": 'nothing fetched yet'
}
};
}
componentDidMount() {
this._makeApiCall(this.props.endpoint);
}
_makeApiCall(endpoint) {
fetch(endpoint).then(function(response) {
this.setState({
response: response
});
}.bind(this))
}
render() {
return <Child data = {
this.state.response
}
/>;
}
}
class Child extends React.Component {
constructor(props) {
super(props);
this.state = {
data: props.data
};
}
render() {
console.log(this.state.data, 'new data');
return ( < span > {
this.state.data.title
} < /span>); …
Run Code Online (Sandbox Code Playgroud) 我使用react-router-dom在我的主React组件中得到了相当多的TypeScritp错误.所有子组件都返回错误:
error TS2322: Type 'typeof NotFound' is not assignable to type 'StatelessComponent<void | RouteComponentProps<any>> | ComponentClass<void | RouteComponentProps<a...'.
Type 'typeof NotFound' is not assignable to type 'ComponentClass<void | RouteComponentProps<any>>'.
Types of parameters 'props' and 'props' are incompatible.
Type 'void | RouteComponentProps<any> | undefined' is not assignable to type '{} | undefined'.
Type 'void' is not assignable to type '{} | undefined'.
error TS2322: Type 'typeof Index' is not assignable to type 'StatelessComponent<void | RouteComponentProps<any>> | ComponentClass<void | RouteComponentProps<a...'.
Type 'typeof …
Run Code Online (Sandbox Code Playgroud) 我有一个登陆页面,我想要做的就是在完成播放后淡出对象以显示下面的背景.使用jQuery或任何其他方法淡出标记<video>
或<div>
标记都没问题.
<div id="video">
<video width="100%" height="auto" autoplay="autoplay">
<source src="monarch.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>
<source src="monarch.ogv" type='video/ogg; codecs="theora, vorbis"'>
</video>
</div>
Run Code Online (Sandbox Code Playgroud) 我正在为一个项目设置 stylelint,从 cli 运行时,一切都按预期工作:
$ stylelint 'css/**/*.css' --fix
css/style.css
20:18 × Expected newline after ":" with a multi-line declaration declaration-colon-newline-after
...
...
Run Code Online (Sandbox Code Playgroud)
但是,当作为npm script
无输出运行时(超出记录命令)并且错误似乎被忽略:
$ npm run stylelint
> project lint:css path/project
> stylelint 'css/**/*.css' --fix
Run Code Online (Sandbox Code Playgroud)
包.json
"scripts": {
...
"stylelint": "stylelint 'css/**/*.css' --fix"
},
Run Code Online (Sandbox Code Playgroud)
知道当 stylelint 作为 npm 脚本运行时如何获取控制台输出并退出错误吗?
我正在研究一个保存到 Mongo的评论系统,它建议以下结构:
{
_id: ObjectId(...),
discussion_id: ObjectId(...),
slug: '34db',
posted: ISODateTime(...),
author: {
id: ObjectId(...),
name: 'Rick'
},
text: 'This is so bogus ... '
}
Run Code Online (Sandbox Code Playgroud)
我想保存author.id
为ObjectId
用户评论的,我在请求中有这个值req.user._id
我需要给我的 Comment 模型什么数据类型才能接受这个值?
我试过:
const authorSchema = new Schema({
id: ObjectId,
username: String
});
Run Code Online (Sandbox Code Playgroud)
但这给 ReferenceError: ObjectId is not defined
我看到ObjectId 列为有效的架构类型但是,它仅在自动生成时出现。
将user._id
ObjectId存储在注释中的正确方法是什么author.id
,或者是否有更好的方法来完全存储引用?
我希望使用Google表格CSV作为数据源。我想在客户端上获取CSV数据,然后将其转换为JSON。
我可以提取CSV,该返回ReadableStream
。但是,我不确定如何正确读取该响应并将其转换为JSON。
我找到了一个npm软件包,该软件包应有助于将CSV数据转换为JSON,但是花一点时间处理流。
示例:https://jsfiddle.net/21jeq1h5/3/
谁能指出我正确的使用方向ReadableStream
?
我喜欢将我的app入口点用作全局州商店.将信息传递给儿童作为道具.
使用react-router 4,如何将prop数据发送到渲染的组件.以类似的方式:
<Route Path=“/someplace” component={someComponent} extra-prop-data={dataPassedToSomeComponent} />
Run Code Online (Sandbox Code Playgroud)
我已经看到了旧版本的react-router的一些janky变通办法,似乎已被弃用.
在v4中执行此操作的正确方法是什么?
我正在尝试使用$addToSet
mongoose 将新对象插入到 mongo 中的数组中:
我有两个模型:
var itemSchema = mongoose.Schema({
itemId: Number,
save_date: {type: Date, default: Date.now}
});
var UserSchema = new Schema({
...
items: [itemSchema]
});
var User = mongoose.model('User', UserSchema);
Run Code Online (Sandbox Code Playgroud)
我想使用 mongoose 将一个添加item
到items
数组中,但前提是该项目不存在。
目前, using$addToSet
仍在添加重复项,因为我认为每个项目的 save_date 戳都不同:
User.findByIdAndUpdate(
id,
{$addToSet: {item: {itemId: newItem} } },
{upsert: true},
function (err, saveItem){
if (err) {return handleError(err)};
res.send(saveItem);
}
);
Run Code Online (Sandbox Code Playgroud)
这会导致用户输入:
"name": "Vinnie James"
"items" : [
{
"itemId" : 123,
"_id" …
Run Code Online (Sandbox Code Playgroud) homebrew
再次第三次破坏了python。我现在遇到使依赖项再次起作用的问题。此时,我无法安装yaml
。
Collecting yaml
Could not find a version that satisfies the requirement yaml (from versions: )
No matching distribution found for yaml
有人说过尝试其他建议pyaml
,但又再次尝试导入但yaml
失败了。
Traceback (most recent call last):
File "script.py", line 13, in <module>
import pyaml
File "/~/virtualenv/project/lib/python2.7/site-packages/pyaml/__init__.py", line 6, in <module>
import os, sys, io, yaml
ImportError: No module named yaml
任何人都有一个想法如何解决这个问题?
我是一个相对较新的Java,作为一个JS开发人员,在SpringBoot应用程序上工作,我看到了一个让我的好奇心高峰的模式:
在其中Application.java
有几个import
类,然后exclude
在其中标记@SpringBootApplication
,例如
import org.springframework.boot.autoconfigure.data.database.DataBaseAutoConfiguration;
...
@SpringBootApplication(
exclude = {DataBaseAutoConfiguration.class, ...}
)
Run Code Online (Sandbox Code Playgroud)
DataBaseAutoConfiguration
除了这里,代码库中没有其他任何地方引用.
有人可以解释这种模式的目的吗?import
这个类感到奇怪,然后立即exclude
在配置中
为什么不喜欢这样的:
exclude = {"DataBaseAutoConfiguration", ...}
然后在Spring中查找要忽略的类,避免明显的"无用"导入?
要么:
// import nothing
@SpringBootApplication
Run Code Online (Sandbox Code Playgroud) reactjs ×3
express ×2
javascript ×2
mongodb ×2
mongoose ×2
node.js ×2
csv ×1
homebrew ×1
html5 ×1
html5-video ×1
java ×1
jquery ×1
json ×1
npm ×1
npm-scripts ×1
package.json ×1
python ×1
python-2.7 ×1
react-router ×1
spring-boot ×1
stream ×1
stylelint ×1
typescript ×1
video ×1