小编Nat*_*at8的帖子

this.setState未定义

我一直看到使用=>或.bind(this)的答案,但这些解决方案都没有奏效.

import React, { Component } from 'react';
import { View, Text, TextInput, StyleSheet } from 'react-native';

export default class MyWeatherApp extends Component {
  constructor(props) {
  super(props);

  this.state = {};
}

getInitialState() {
  return {
    zip: '',
    forecast: null,
  };
}

_handleTextChange(event) {
  var zip = event.nativeEvent.text;
  this.setState({zip: zip});
}
Run Code Online (Sandbox Code Playgroud)

解:

_handleTextChange = (event) => {
  var zip = event.nativeEvent.text;
  this.setState({zip: zip});
  alert('click');
}
Run Code Online (Sandbox Code Playgroud)

reactjs react-native

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

无法急切加载多态关联

我收到错误无法急切加载多态关联:messageable_fromuser

online = Message.all.joins(:messageable_fromuser)
Run Code Online (Sandbox Code Playgroud)

我试过

online = Message.all.includes(:messageable_fromuser)
Run Code Online (Sandbox Code Playgroud)

但它不包括结果中连接的表。使用包含时,我在日志中看到两个查询。我不知道为什么人们建议使用包含来急切加载。两个查询如何连接任何东西?

join ruby-on-rails polymorphic-associations

8
推荐指数
3
解决办法
7128
查看次数

link_to url helper 在 Rails 4 的 render_to_string 中不起作用

在控制器外部渲染视图时,我试图让 link_to 工作。我尝试了在互联网上找到的几种不同的解决方案。您可以看到已注释掉一项尝试。

它不断导致: nil:NilClass 的未定义方法`host'

    ac = ApplicationController.new
    ac.class.include Rails.application.routes.url_helpers

    #context = Rails.configuration.paths['app/views']
    #view = ActionView::Base.new(context)
    #view.class.include Rails.application.routes.url_helpers
    #view.render :layout => 'layouts/pdf.html.haml', :template => 'reports/show.pdf.haml', locals: {alerts:@alerts}

    ac.render_to_string(:layout => 'layouts/pdf.html.haml', :template => 'reports/show.pdf.haml', locals: {alerts:@alerts})
Run Code Online (Sandbox Code Playgroud)

我也试过骑过课。ActionView::Base 的东西似乎都不起作用。

class ViewRenderer < ActionView::Base
  include Rails.application.routes.url_helpers
  include ApplicationHelper

  def default_url_options
     {host: Rails.application.routes.default_url_options[:host]}
  end
end
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails-4

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

如何从活动管理员中删除资源

我之前创建了资源

rails g active_admin:resource Question
Run Code Online (Sandbox Code Playgroud)

如何删除它?

ruby-on-rails activeadmin

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

clojure require不设置命名空间oauth

如何测试require是否在clojure中工作.REPL中的要求返回nil.我不知道零是否意味着它有效.oauth的命名空间似乎没有设置.

错误

引起:java.lang.RuntimeException:没有这样的命名空间:oauth

(ns hello.core)
(defn -main
  []

  (require 'twitter '[oauth.client :as oauth])

  ;; Make a OAuth consumer
  (def oauth-consumer (oauth/make-consumer <key>
                                           <secret>
                                           "https://api.twitter.com/oauth/request_token"
                                           "https://api.twitter.com/oauth/access_token"
                                           "https://api.twitter.com/oauth/authorize"
                                           :hmac-sha1))
Run Code Online (Sandbox Code Playgroud)

clojure

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