如何在ExtReact中的FormPanel中输入onSubmit处理程序?

时间:2018-04-27 09:33:15

标签: javascript reactjs extreact

所以,我只想在ExtReact中为FormPanel执行onSubmit事件。但它就像我在内联onSubmit函数中甚至不能控制console.log,即onSubmit永远不会被执行。有什么想法吗?

这些是代码中最重要的部分:

  1. FormPanelComponent:
  2. using System;
    using System.Linq;
    using System.Xml.Linq;
    
    class Program
    {
        static void Main()
        {
            var doc = XDocument.Load("test.xml");
            var directories = doc.Descendants("dir");
    
            foreach (var dir in directories)
            {
                var parts = dir
                    .AncestorsAndSelf() // All the ancestors of this element, and itself
                    .Reverse()          // Reversed (so back into document order)
                    .Select(e => e.Attribute("name").Value); // Select the name
                var path = string.Join("/", parts);
                Console.WriteLine(path);
            }
        }   
    }
    
    1. 我的ItemGroupModel:
    2. import React from 'react';
      import ItemGroupModel from './ItemGroupModel';
      import { FormPanel, TextField, Button } from '@extjs/ext-react';
      
      
      class FormPanelComponent extends React.Component {
      
          render(){
              return(
                  <FormPanel 
                  record={ItemGroupModel} 
                  standardSubmit = {true} 
                  onSubmit={function(formPanel, result, e, eOpts){
                      console.log("Hello"); //Nothing is console.logged
                      console.log(formPanel), //Nothing is console.logged
                      console.log(result), //Nothing is console.logged
                      console.log(e);//Nothing is console.logged
                      console.log(eOpts); //Nothing is console.logged
                  }}>
                      <TextField name="description" label="Description: " labelAlign= "top" />
                      <TextField name="name" label="Name: " labelAlign="top" />
                      <Button text="Submit"/>
                  </FormPanel>
              )
          }
      }
      
      export default FormPanelComponent;
      

1 个答案:

答案 0 :(得分:0)

class FormPanelComponent extends React.Component {

submit = (ormPanel, result, e, eOpts) => console.log(ormPanel, result, e, eOpts)

render(){
    return(
        <FormPanel 
        record={ItemGroupModel} 
        standardSubmit = {true} 
        onSubmit={(formPanel, result, e, eOpts) => this.submit(formPanel, result, e, eOpts)}>
            <TextField name="description" label="Description: " labelAlign= "top" />
            <TextField name="name" label="Name: " labelAlign="top" />
            <Button text="Submit"/>
        </FormPanel>
    )
}