小编Col*_*amp的帖子

使用反应路由器V4以编程方式导航

我刚刚react-router从v3 更换为v4.
但我不知道如何以编程方式导航到一个成员函数Component.即在handleClick()功能中我想/path/some/where在处理一些数据后导航到.我曾经这样做过:

import { browserHistory } from 'react-router'
browserHistory.push('/path/some/where')
Run Code Online (Sandbox Code Playgroud)

但我在v4中找不到这样的接口.
如何使用v4导航?

ecmascript-6 reactjs react-router-v4

313
推荐指数
13
解决办法
22万
查看次数

Swift 3:十进制到Int

我尝试使用以下代码将Decimal转换为Int:

Int(pow(Decimal(size), 2) - 1) 
Run Code Online (Sandbox Code Playgroud)

但我得到:

.swift:254:43: Cannot invoke initializer for type 'Int' with an argument list of type '(Decimal)' 
Run Code Online (Sandbox Code Playgroud)

在这里我知道pow正在返回a Decimal但似乎Int没有构造函数和成员函数可以转换DecimalInt.
如何在Swift 3中将Decimal转换为Int?

nsdecimalnumber ios swift swift3

25
推荐指数
4
解决办法
2万
查看次数

猫鼬:如何使用聚合并一起找到

我如何在Mongoose中使用聚合find一起?
即我有以下架构:

const schema = new Mongoose.Schema({
  created: { type: Date, default: Date.now() },
  name: { type: String, default: 'development' }
  followers: [{ type: Mongoose.Schema.ObjectId, ref: 'Users'}]
...
})

export default Mongoose.model('Locations', schema)
Run Code Online (Sandbox Code Playgroud)

如何仅使用字段name和查询用户followers_count.
followers_count:长度followers.

在那里,我知道我们可以使用select来获得该字段name.
我们怎么能算得上followers

mongoose mongodb node.js mongodb-query aggregation-framework

22
推荐指数
2
解决办法
3万
查看次数

使用Jest测试失败,错误:观察文件更改时出错:EMFILE

我试着为React.js应用程序编写测试.一切都很顺利但是在用Git跟踪目录之后(用它做了一个Git回购).测试失败,出现以下错误

2017-01-15 05:05 node[1278] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2017-01-15 05:05 node[1278] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: Error watching file for changes: EMFILE
    at exports._errnoException (util.js:1022:11)
    at FSEvent.FSWatcher._handle.onchange (fs.js:1406:11)
Run Code Online (Sandbox Code Playgroud)

我确信这是因为.git目录,因为当我删除.git目录时它正在运行而没有错误.似乎在观看文件时发生异常.我的开发环境是MacOS 10.12.2和节点6.9.4.我该如何解决这个问题?

node.js ecmascript-6 reactjs jestjs

14
推荐指数
1
解决办法
4346
查看次数

如何将Code Climate测试覆盖率报告覆盖到同一个提交

我使用的CC-测试记者上传的测试覆盖率结果Code ClimateCircleCI

但是运行相同的构建失败并显示以下消息:

Error: response from https://api.codeclimate.com/v1/test_reports.
HTTP 409: A test report for commit 
858d3fa0c92ec5a546bde3991f57523768dac0c2 already exists
Run Code Online (Sandbox Code Playgroud)

如何让它通过CI脚本或覆盖它而不会失败?

circleci code-climate

10
推荐指数
0
解决办法
246
查看次数

apt-get:如何绕过按 ENTER

我在 CircleCI 中Press [ENTER] to continue or ctrl-c to cancel adding it使用apt-get时得到了。我怎样才能自动绕过它?
我尝试使用-y但没有效果!

linux shell circleci ubuntu-16.04

6
推荐指数
2
解决办法
3123
查看次数

ElasticSearch:ignore_malformed 不起作用

我试图ignore_malformed在 ElasticSearch Mapping 中输入一个字段的属性。

EClient.indices.putMapping(
  {
    index: 'activities',
    type: 'user',
    body: {
      properties: {
        meta: {
          type: 'object',
          ignore_malformed: true, // meta is dynamic
        },
      },
    },
  },
  (err, res) => {
    console.info('Put Mapping Error:', err);
    console.info('Put Mapping Res:', res);
  }
);
Run Code Online (Sandbox Code Playgroud)

但我得到

response: '{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"Mapping definition for [meta] has unsupported parameters:  [ignore_malformed : true]"}],"type":"mapper_parsing_exception","reason":"Mapping definition for [meta] has unsupported parameters:  [ignore_malformed : true]"},"status":400}'
Run Code Online (Sandbox Code Playgroud)

根据文档:ignore_malformed它应该可以工作。有人可以告诉我我的代码有什么问题吗?

node.js elasticsearch

5
推荐指数
2
解决办法
3633
查看次数

'... paths.js'在'gulp.src([... paths.js,'!gulpfile.babel.js'],{base:'.'}}'中的含义是什么?

我有以下gulp任务:

// Compile ES6 to ES5 and copy to dist
gulp.task('babel', () =>
  gulp.src([...paths.js, '!gulpfile.babel.js'], { base: '.' })
    .pipe(plugins.newer('dist'))
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.babel())
    .pipe(plugins.sourcemaps.write('.', {
      includeContent: false,
      sourceRoot(file) {
        return path.relative(file.path, __dirname);
      }
    }))
    .pipe(gulp.dest('dist'))
);
Run Code Online (Sandbox Code Playgroud)

根据Gulp Doc(gulp.src),我了解到gulp.src会发出匹配提供的glob或glob数组的文件.
但我无法理解'... paths.js'的含义.项目目录中没有以"paths.js"命名的文件.

有没有人可以帮助我理解它?

javascript node.js ecmascript-6 gulp

4
推荐指数
1
解决办法
103
查看次数

iOS:如何使用 IQKeyboardManager 更改要聚焦的 UITextField 的顺序

我已经把多UITextFieldsUIViewController故事板。
我正在使用IQKeyboardManagerUITextFields在它们聚焦时在键盘上滚动。

IQKeyboardManager 工具栏

当我单击键盘工具栏中的下一个按钮时,另一个UITextField正在获得焦点,而当前一个失去焦点。

我怎样才能控制焦点的顺序的的UITextFieldS按键盘工具栏按钮?

ios uistoryboard swift iqkeyboardmanager

3
推荐指数
1
解决办法
906
查看次数

如何将CSS类添加或应用于整个HTML

我通常会在HTML文档的主体中添加一个类,如下所示:

document.body.classList.toggle('darkClass', this.props.isDark)
Run Code Online (Sandbox Code Playgroud)

但我不知道如何获得整个html元素.如何在Javascript中引用它?

var html = ?
html.classList.toggle(...)
Run Code Online (Sandbox Code Playgroud)

html javascript dom

1
推荐指数
1
解决办法
61
查看次数