小编Par*_*gra的帖子

检测用户何时使用React js滚动到div的底部

我有一个不同部分的网站.我正在使用segment.io来跟踪页面上的不同操作.如何检测用户是否已滚动到div的底部?我尝试过以下但是当我滚动页面时它似乎被触发而不是当我到达div的底部时.

componentDidMount() {
  document.addEventListener('scroll', this.trackScrolling);
}

trackScrolling = () => {
  const wrappedElement = document.getElementById('header');
  if (wrappedElement.scrollHeight - wrappedElement.scrollTop === wrappedElement.clientHeight) {
    console.log('header bottom reached');
    document.removeEventListener('scroll', this.trackScrolling);
  }
};
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

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

SyntaxError:意外的令牌导入

当我运行index.js时给出错误SyntaxError: Unexpected token import.虽然我使用babel将ES6转换为ES5.

的package.json

{
  "name": "espract",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "build": "babel src -d lib"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-cli": "^6.3.17"
  }
}
Run Code Online (Sandbox Code Playgroud)

Person.js

'use strict';

module.exports = class Person {
    constructor(firstname, lastname) {
        this.firstName = firstname;
        this.lastName = lastname;
    }

    greet() {
        console.log(`Hello, ${ this.firstName } ${ this.lastName }`);
    }
};
Run Code Online (Sandbox Code Playgroud)

index.js

import * as Person from './lib/Person';


//es class inherit Person
class Policeman extends Person {

    constructor(firstname, …
Run Code Online (Sandbox Code Playgroud)

javascript node.js ecmascript-6 babeljs

14
推荐指数
0
解决办法
9万
查看次数

uninitialized constant> ActionCable :: Server :: Configuration :: ApplicationCable

当我运行服务器时,它的抛出错误显示在下面的日志中.我google了很多但没有理由支持它.有人请说清楚.

的Gemfile

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '>= 5.0.0.beta1', '< 5.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'

gem 'active_model_serializers', '~> 0.10.0.rc1'

group :development, :test do
  gem 'byebug'
end
gem 'puma'
group :development do
  gem 'spring'
end
Run Code Online (Sandbox Code Playgroud)

日志:

/home/pd/.rvm/gems/ruby-2.2.4/gems/actioncable-5.0.0.beta1/lib/action_cable/server/configuration.rb:15:in
`initialize': uninitialized constant
ActionCable::Server::Configuration::ApplicationCable (NameError)    from
/home/pd/.rvm/gems/ruby-2.2.4/gems/actioncable-5.0.0.beta1/lib/action_cable/server/base.rb:16:in `new'  from
/home/pd/.rvm/gems/ruby-2.2.4/gems/actioncable-5.0.0.beta1/lib/action_cable/server/base.rb:16:in `block in <class:Base>'    from
/home/pd/.rvm/gems/ruby-2.2.4/gems/activesupport-5.0.0.beta1/lib/active_support/core_ext/module/attribute_accessors.rb:72:in
`block in mattr_reader'     from
/home/pd/.rvm/gems/ruby-2.2.4/gems/activesupport-5.0.0.beta1/lib/active_support/core_ext/module/attribute_accessors.rb:55:in
`each'  from
/home/pd/.rvm/gems/ruby-2.2.4/gems/activesupport-5.0.0.beta1/lib/active_support/core_ext/module/attribute_accessors.rb:55:in
`mattr_reader'  from
/home/pd/.rvm/gems/ruby-2.2.4/gems/activesupport-5.0.0.beta1/lib/active_support/core_ext/module/attribute_accessors.rb:208:in
`mattr_accessor'    from
/home/pd/.rvm/gems/ruby-2.2.4/gems/actioncable-5.0.0.beta1/lib/action_cable/server/base.rb:16:in …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails ruby-on-rails-5 actioncable

11
推荐指数
3
解决办法
4255
查看次数

带有错误栏的Matplotlib直方图

matplotlib用这个pyplot.hist()函数创建了一个直方图.我想sqrt(binheight)在条形图中添加bin height()的Poison错误平方根.我怎样才能做到这一点?

.hist()包含的返回元组return[2]- > 1个Patch对象的列表.我只能发现可以通过创建的条形图添加错误pyplot.bar().

matplotlib histogram

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

无法转储Singleton - cached_resource gem

使用cached_resource gem缓存活动资源.

用户模型

class User < ActiveResource::Base
  cached_resource

  class teachers < SimpleDelegator
    attr_accessor :teacher_id

    def initialize(attributes = {}, _persisted = true)
      @teacher_id = attributes['teacher_id']
      super(User.find(@teacher_id))
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

我正在尝试缓存用户资源.

/users/:user_id

每当我调用/ users /:user_id端点时它就会给出错误单例不能在行中转储 super(User.find(@teacher_id))

请建议是否有任何其他gem可以帮助我缓存activeresource调用.

ruby-on-rails activeresource ruby-2.2 rails-4-2-1 cached-resource

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

使用ruby on rails将boolean值保存到postgres数据库

我一直在做一个旧的rails项目.由于我有一段时间没有使用过rails,我有点生疏,需要一些帮助.

问题是我在电子商务网站上添加了一个选择选项.

后端是由 active admin

当客户检查其产品时.他可以选择在商店取货或送货.

我希望订单在后端显示是否应该发送产品或者是否在商店领取产品.

我有点卡在这里,交付选项似乎没有保存到数据库....如果有人可以帮助我这将是非常好的.

这是拾取选项的html.它位于views/orders/_form.html.erb

<div class="col-md-5 pick-up-buttons" id="country_div">
  <li>
    <%= f.radio_button :pick_up, "1", checked: false, data: { question: "Pick up your items in the store" } %> 
    <%= f.label :pick_up, "Pick up your items in the store" %>
  </li>
  <li>
    <%= f.radio_button :pick_up, "0", checked: true,  data: { question: "Send the items by mail" } %> 
    <%= f.label :pick_up, "Send the items by mail" %>
  </li>
</div> 
Run Code Online (Sandbox Code Playgroud)

这是schema.rb文件 的一部分

create_table "orders", force: …
Run Code Online (Sandbox Code Playgroud)

ruby postgresql ruby-on-rails radio-button e-commerce

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

Rails图像和跟踪保护

我用devise和facebook auth制作了一个示例应用程序.我想将fb个人资料照片显示为用户的头像,并且它在Chrome和IE中工作.但是在firefox中我看到了关于"跟踪保护"的警告 - "连接不安全".

我写了一个简单的方法:

def avatar_for(user)
  avatar_url = user.image
  image_tag(avatar_url, alt: user.name, class: "avatar") unless user.image.nil?
end
Run Code Online (Sandbox Code Playgroud)

如何使这种方法/连接安全?

编辑:这正是max写的:使用https地址vis secure_image_url会删除Firefox中"跟踪保护"警告中的警告,但不显示任何图像.

ruby security ruby-on-rails

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

完整日历时间间隔应为1小时,从6:30开始

我尝试了这个实现完整日历实现.

    $("#available_classes_calendar").fullCalendar({
        header: {
             left   : 'prev,next',
             center : 'title'
            },
        defaultView: 'agendaWeek',
        views:{
            agenda:{
                allDaySlot: false,
                minTime: "06:30:00",
                maxTime: "24:00:00",
                slotDuration: "00:60:00"
            }
        }
    });
Run Code Online (Sandbox Code Playgroud)

在这个全天列应该从早上6:30开始,间隔时隙应该是1小时.

因此,全天列应如下所示:

早上6:30,早上7:30,上午8:30...晚上11:30

我尝试了很多解决方案,但无法实现这一目标.

如果需要任何其他信息来解决此问题,请与我们联系.

谢谢 @lucasnadalutti小提琴的截图

javascript jquery fullcalendar

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

在验证失败后调用渲染后Rails刷新页面

所以我有一个控制器动作看起来像这样:

def create
  @term = Term.new(term_params)
  if @term.save
    redirect_to(@term)
  else
    render :new
  end
end
Run Code Online (Sandbox Code Playgroud)

验证失败时,将呈现新的操作视图,用户可以看到所做的错误.问题是,这也会将URL更改为,localhost:3000/terms因此当用户由于某种原因想要刷新页面时,rails会想要将该用户重定向到术语index页面.是否有一种简单的方法可以new term在刷新后让用户保持在页面上?

我实际上没有index页面,terms因为我不需要它,所以在这种情况下这整个情况都会引发错误.

ruby-on-rails

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

document.normalize究竟做了什么?

我读到document.normalize 删除空文本节点,并加入相邻节点.

这究竟是什么意思?

javascript

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