小编Pau*_*000的帖子

touch .gitignore 不创建文件

我正在尝试设置一个 React 开发环境,我收到的一条指令是在终端中输入我的目录并输入以下代码:

\n\n
touch .gitignore\n
Run Code Online (Sandbox Code Playgroud)\n\n

当我创建一个带有名称和扩展名(例如 )的文件时, touch 命令工作正常,index.html但由于这似乎只是一个扩展名,所以什么也没有发生。

\n\n

显然这是一个关于上传到 GitHub 的重要文件 - 有人可以帮忙吗?

\n\n
\n\n

更新:我创建了x.gitignore,然后尝试删除x,OSX 会弹出一个对话框:

\n\n
You can\xe2\x80\x99t use a name that begins with a dot \xe2\x80\x9c.\xe2\x80\x9d, because these names are reserved for the system. Please choose another name.\n
Run Code Online (Sandbox Code Playgroud)\n

terminal file-extension touch gitignore reactjs

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

推送到Heroku否认 - "未能将一些引用推到'heroku'

我应该首先说我对Heroku来说是全新的,而且现在对我来说都很陌生.

无论如何,我已经完成了Heroku入门教程,上传了一个克隆git repo,这很好用.

我现在正试图用我自己的一些代码完成这个,但是很挣扎.

  1. 首先,我在bash中访问我的app目录.
  2. 然后我跑了heroku create.这很成功.
  3. 然后我git push heroku master按照教程中的说明运行,并收到以下错误:

error: src refspec master does not match any.

error: failed to push some refs to 'heroku'

如果有人能解释我在这里缺少的东西,我将不胜感激?提前致谢.

git push github heroku

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

为什么使用Angular Service来收集信息,而不仅仅是$ http?

两个选项,哪个更好,为什么:

例A.

  1. 应用模块
  2. 包含模型数据的服务
  3. 控制器从服务中调用数据

文件1 Users.js::

      angular.module('users', []);
Run Code Online (Sandbox Code Playgroud)

文件2 userService.js::

angular.module('users').service('userService', ['$q', UserService]);

  function UserService($q) {
    var users = [
      {
        name: 'Bob Smith',
        age: 26,
        address: 'London',
      },
      {
        name: 'John Simpson',
        age: 41,
        address: 'New York',
      },
      {
        name: 'Maria West',
        age: 36,
        address: 'Chicago',
      }
    ];

    // Promise-based API
    return {
      loadAllUsers : function() {
        // Simulate async nature of real remote calls
        return $q.when(users);
      }
    };
  }

})();
Run Code Online (Sandbox Code Playgroud)

文件3 UserController.js::

          angular.module('users').controller('UserController', ['$scope', …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs angularjs-service angularjs-http

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

响应表单,提交对象,然后将其推送到数组

我是 React 的新手,不确定如何执行此操作。

我有一组对象,这些对象已映射并在我的视图中呈现。我想要做的是设置一个表单,将每个字段的值提交给新对象的相应属性,但我不确定如何执行此操作。

这是我在视图中呈现的初始数据:

contactArray = [
  {
    name: 'John'
    email: 'john@email.com'
    number: 111-111-111
  },
  {
    name: 'Dave'
    email: 'dave@email.com'
    phone: '222-222-222'
  }
]
Run Code Online (Sandbox Code Playgroud)

然后我有一个表格:

class InputForm extends Component {
  render() {
    return (   
        <form>
          <input type='text' onChange={this.handleChange}/>
          <input type='text' onChange={this.handleChange}/>
          <input type='text' onChange={this.handleChange}/>
          <button type='submit' onSubmit={this.handleSubmit}>SUBMIT</button>
        </form>
    ) 
  }
Run Code Online (Sandbox Code Playgroud)

然后我假设我将状态声明为:

constructor(props) {
  super(props);
  this.state = {
    name: '',
    email: '',
    phone: ''
  }
}
Run Code Online (Sandbox Code Playgroud)

然后提交功能我真的不知道怎么处理...

handleSubmit() {
  // not sure about this...
  this.setState({
    name: // ????
    email: // …
Run Code Online (Sandbox Code Playgroud)

javascript forms arrays submit reactjs

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

从数组中删除元素(拼接)

关于.splice()方法的基本问题,以及如何最好地从数组中删除元素.

我想从数组中删除一个项目,.splice()但是当我这样做时,我希望原始数组减去已删除的元素..splice()返回已删除的元素.

var arr = [1, 2, 3, 4, 5, 6, 7]
var newArr = arr.splice(3, 1)

console.log(newArr) // [4]

// whereas I want [1, 2, 3, 5, 6, 7]
Run Code Online (Sandbox Code Playgroud)

什么是最好,最有说服力的方法呢?

javascript arrays element splice

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

同时使用http-server和node express服务器

我已经看到了节点快速服务器的以下设置:

server.js

import { Server } from 'http'; 
import Express from 'express'; 

const app = new Express(); 
const server = new Server(app);
Run Code Online (Sandbox Code Playgroud)

既然可以直接运行express,那么将express服务器作为http服务器的参数返回有什么好处呢?

httpserver node.js express server

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

Redux reducer无法删除数组元素

我在尝试让我的reducer在Redux中正常工作时遇到了问题.我是Redux的新手,所以我可能会错过一些简单的东西,但是我已经玩了一段时间并且无法弄清楚出了什么问题.

这是我的过程:

定义参数:

首先,我定义了我需要的索引值.记录时,返回正确的数字......

const thisCommentIndex = parseInt(comments.indexOf(comment))
Run Code Online (Sandbox Code Playgroud)

功能调用:

<div onClick={this.props.removeComment.bind(null, thisCommentIndex)}></div>
Run Code Online (Sandbox Code Playgroud)

行动:

export function removeComment(index) {
   return {
      type: 'REMOVE_COMMENT',
      index
   }
}
Run Code Online (Sandbox Code Playgroud)

减速器:

function comments(state = [], action) {
   switch(action.type) {
      case 'REMOVE_COMMENT' :
         console.log('removing comment with index of ' + action.index)
         return [
            ...state.slice(0, action.index), // why isn't this working???
            ...state.slice(action.index)
         ]
      default :
         return state
   }
   return state;
}
Run Code Online (Sandbox Code Playgroud)

当我console.log('removing COMMENT with index of ' + action.index),它正确记录action.index,我期望的整数.但该函数不会按预期删除元素.

奇怪的是,如果我只是简单地传递数组索引,它工作正常(删除数组元素).(我会这样做,但由于我设置我的应用程序的方式,在这种情况下它将无法工作).

我在这里错过了什么吗?任何帮助赞赏.

javascript arrays reducers reactjs redux

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

推送回购失败(Git/GitHub)

我正在尝试将我的文件推送到GitHub上的repo,我收到一个错误.谁能帮助解释我做错了什么?

正在抛出一条错误消息,但我无法理解它(我是Git的新手......)

git push -u origin master

> To https://github.com/URL  ! [rejected]        master -> master (fetch
> first) error: failed to push some refs to 'https://URL' hint: Updates
> were rejected because the remote contains work that you do hint: not
> have locally. This is usually caused by another repository pushing
> hint: to the same ref. You may want to first integrate the remote
> changes hint: (e.g., 'git pull ...') before pushing again. hint: See
> the …
Run Code Online (Sandbox Code Playgroud)

git push github

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