小编Het*_*nti的帖子

如何从ReactJS中的onClick函数调用另一个组件

我正在学习Reactjs.我用rails实现了一个示例反应应用程序.我已经搜索了很多找到解决方案,但我没有找到任何解决方案.我想从onClick函数中调用另一个组件.但什么都没发生.这可能是我试图实现的吗?如果是,那么请指出我错误的地方,如果没有,那么我可以实施哪种方式.这是我的代码:

var Comment = React.createClass({
  render: function () {
    return (
      <div id={"comment_"+ this.props.id }>
        <h4>{ this.props.author } said:</h4>
        <p>{ this.props.desc }</p>
        <a href='' onClick={this.handleDelete}>Delete</a> | #this is for delete which works great
        <a href='' onClick={this.handleEdit}>Edit</a> 
         # If I put here then it works fine <UpdateComments comments={ this.props} /> but I don't want it here
      </div>
    )
  },
  handleDelete: function(event) {
    $.ajax({
      url: '/comments/'+ this.props.id,
      type: "DELETE",
      dataType: "json",
      success: function (data) {
       this.setState({ comments: data });
      }.bind(this) …
Run Code Online (Sandbox Code Playgroud)

javascript ruby-on-rails reactjs react-rails

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

删除嵌套模型表格Rails 4中的记录的问题

我正在关注RailsCast#196 Nested Model Form Part 1.我给出了控制器和模型的相同名称,它是所有属性.但现在当我尝试进行编辑并删除问题时.如果我选中该复选框,则不会删除该问题.

像这样: 在此输入图像描述 模型:

class Survey < ActiveRecord::Base
  has_many :questions, :dependent => :destroy
  accepts_nested_attributes_for :questions, :reject_if => lambda {|a| a[:content].blank?} , :allow_destroy => true
end

class Question < ActiveRecord::Base
  belongs_to :survey
end
Run Code Online (Sandbox Code Playgroud)

调查控制员:

class SurveysController < ApplicationController
  before_action :set_survey, only: [:show, :edit, :update, :destroy]

  def index
    @surveys = Survey.all
  end

  def show
  end

  def new
    @survey = Survey.new
    3.times {@survey.questions.build}
  end

  def edit
  end

  def create
    @survey = Survey.new(survey_params)

    respond_to do |format|
      if @survey.save …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails nested-forms railscasts

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