小编dhj*_*dhj的帖子

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

HTML5桌面通知(理想情况下为Angular)

我希望能够向用户发送桌面通知(而不是在浏览器窗口内),我知道我必须让用户选择在chrome中打开对话框问题.

我正在使用MEAN堆栈,并在前端使用browserify/bowserify,我可以在客户端使用bower或npm包.我使用CommonJS模式,因此如果解决方案或示例采用该格式,或者更容易转移到该格式,它将帮助我理解它.

什么是最好的方法来解决这个问题,是否有一个Angular/React插件(我必须承认我找不到自己).

我真的只需要一次显示一个,我很乐意只显示最新的并自动删除那里的任何内容,理想情况下是跨浏览器解决方案(只有在需要时才可以是最新版本).

欢迎任何想法.

javascript html5 notifications angularjs reactjs

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

如何使用Mongoose将json导入MongoDB

我有一些问题,这是什么让它变得棘手,所以......

我正在使用Mongoose和MongoLab,我可以存储数据并检索它很好,但我想要一个允许我做数据库基础种子的系统.

我有为集合创建的模式,但没有运行因为没有数据,所以我似乎无法运行正常的mongoimport,因为尚未创建集合.

我想在我的节点服务器上添加一些东西,这样如果集合不存在或为空,它会为集合加载一个模式,然后为种子数据插入json.

所以我有这个......

var Club = require('./schemas/Club');
Run Code Online (Sandbox Code Playgroud)

我通常使用Club.find或Club.save等工作正常.

我想对一个需要创建的Club集合运行一个对象数组的保存.

我确实研究了mongoose-fixture但是它没有多年更新,并且可能有一种方法可以做到这一点而不需要那么多额外的代码,因为我已经定义了模式,并且json数组已经准备就绪.

这是我列出的成功事件,当我想要进行检查和导入时.

mongoose.connection.on('open', function () {
  console.log('mongoose.connection.opened');
});
Run Code Online (Sandbox Code Playgroud)

另外,要考虑,如果我想创建两个集合,并且当它为第一个集合中的项生成ObjectId()时,我可以想象想要将第二个集合中的那些用作ref.

假设Club对象现在只有一个字符串属性.

// contents of data/club.json
[
  { 'name' : 'Barcelona' },
  { 'name' : 'Real Madrid' },
  { 'name' : 'Valencia' }
]
Run Code Online (Sandbox Code Playgroud)

任何帮助非常感谢

json mongoose mongodb node.js

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

发送ArrayBuffer到S3并放置到signedURL

我正在逐步将文件加载到缓冲区中,该缓冲区有效,但是当ArrayBuffer完成将文件加载到其中时,浏览器崩溃。我需要做的是能够将缓冲区的片段发送buf = this.concatBuffers(buf, buffer);到axios PUT请求,以便我可以将文件逐步上载到s3,而不是将其加载到promise返回的单个变量中(因为超出了内存) 。

如何修改readFileAsBuffer和uploadFileToS3方法之间的链接以执行此操作?

这是我的代码,因此您可以按照此过程进行操作。

concatTypedArrays = (a, b) => {
  const c = new a.constructor(a.length + b.length);
  c.set(a, 0);
  c.set(b, a.length);
  return c;
};

concatBuffers = (a, b) =>
  this.concatTypedArrays(
    new Uint8Array(a.buffer || a),
    new Uint8Array(b.buffer || b),
  ).buffer;

readFileAsBuffer = file =>
  new Promise((resolve, reject) => {
    const fileReader = new FileReader();
    fileReader.file = file;
    let buf = new ArrayBuffer();
    const fileChunks = new FileChunker(file, 2097152);

    fileReader.readAsArrayBuffer(fileChunks.blob());

    fileReader.onload = e => {
      this.onProgress(fileChunks); …
Run Code Online (Sandbox Code Playgroud)

javascript amazon-s3 filereader ecmascript-6 aws-sdk-js

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

在react-router中用连字符匹配路由

我有这样的网址;

http://0.0.0.0/country/bosnia-and-herzegovina-644
Run Code Online (Sandbox Code Playgroud)

这是我的路线声明

<Route path="/country/:countrySlug-:countryId" component={CountryPage} />
Run Code Online (Sandbox Code Playgroud)

所以这不起作用,因为连字符打破了它,我怎样才能改变它,所以我只提取最后一个连字符作为参数,我真的不想改变我的slug生成系统以使用不同的字符,因为这些是最易读的恕我直言,但仅用于信息,而不是内容加载。

谢谢

javascript reactjs react-router

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

Elastic Beanstalk 重定向缺少冒号?

我在 Elastic Beanstalk 中设置了一个网站,但是当我website.com在浏览器中输入 URL 时,它会自动将我定向到https//website.com并且缺少冒号...如果我添加 www.website.com 则它会起作用...或者如果我键入https://www.website.com

.ebextensions/prod01.config文件的内容

files:
  /etc/nginx/conf.d/proxy.conf:
    owner: root
    group: root
    mode: "000644"
    content: |
      # Elastic Beanstalk Managed

      # Elastic Beanstalk managed configuration file
      # Some configuration of nginx can be by placing files in /etc/nginx/conf.d
      # using Configuration Files.
      # http://docs.amazonwebservices.com/elasticbeanstalk/latest/dg/customize-containers.html 


      upstream nodejs {
          server 127.0.0.1:8081;
          keepalive 256;
      }

      server {
          listen 8080;
          server_name website.com;

          if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") {
              set $year $1;
              set $month $2;
              set …
Run Code Online (Sandbox Code Playgroud)

nginx amazon-web-services amazon-elastic-beanstalk

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

KeyboardAvoidingView 不适用于 Expo

我似乎无法使用键盘在我的 React-Native Expo 应用程序中推送内容。我正在通过从我的开发机器发布它来从 expo 应用程序测试它。

尽我所能,当键盘成为焦点时,似乎没有任何东西可以将视图向上推,是否有特定的组件顺序,或者我缺少某些属性;我已经包含了我认为相关的版本、渲染块和样式块。

我正在使用以下版本(最新);

"expo": "^29.0.0",
"react": "16.3.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-29.0.0.tar.gz",
Run Code Online (Sandbox Code Playgroud)

对于登录页面,渲染代码如下所示;

 render() {
    return (
      <SafeAreaView style={styles.flexContainer}>
      <KeyboardAvoidingView
        style={styles.flexContainer}
        behavior="padding"
      >
        <Image style={styles.image} source={require('../../assets/images/backgroundWelcome.png')} role="presentation" />
        <View style={styles.container}>
          <View style={[styles.row, styles.border]}>
            <TextInput 
              placeholder='Email' 
              style={styles.input} 
              onChangeText={(input) => this.setState({email: input})} 
              value={this.state.email} 
            />
          </View>
          <View style={[styles.row, styles.border]}>
            <TextInput 
              placeholder='Password'
              style={styles.input}
              secureTextEntry={true}
              onChangeText={(input) => this.setState({password: input})}
              value={this.state.password} 
            />
          </View>

          <View style={styles.row}>
            <StyledButton callback={this.handleLogin} title='Log In'/>
          </View>

        </View>
      </KeyboardAvoidingView>
      </SafeAreaView>
    )
  }
Run Code Online (Sandbox Code Playgroud)

这些是相关的样式;

  root: {
    flex: 1,
    alignItems: 'center',
    backgroundColor: '#fff', …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-native expo

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

更新 redux 状态对象属性

如何在 redux 中更新对象的属性并保留对象的其余部分..

const appReducer = (state = initialState, action) => {
  switch (action.type) {
    case 'LOGIN_SUCCESS':
      return Object.assign({}, state, {
        user: { loggedIn: true, level: 'default' },
      });

    case 'UPDATE_PACKAGE': {
      // add a new value for the user.level which would be in action.level
      return { ...state, level: action.level };
    }

    default:
      return state;
  }
};
Run Code Online (Sandbox Code Playgroud)

所以我希望 UPDATE_PACKAGE 更改 redux 存储级别属性的内容...但它没有改变...

javascript ecmascript-6 reactjs redux react-redux

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