首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DevExtreme按钮的事件看不到组件的字段

DevExtreme按钮的事件看不到组件的字段
EN

Stack Overflow用户
提问于 2022-07-29 12:53:48
回答 1查看 323关注 0票数 0

我有一些字段、方法和按钮事件的组件。这是我的组成部分:

代码语言:javascript
复制
export class MyClass implements OnInit, AfterViewInit {
  @ViewChild(DxDataGridComponent, { static: true })
  dataGrid: DxDataGridComponent;
  myArr: Array<string>
  //some fields here...

  constructor(
    
  //some things
  ) {

    //some code in contructor
    }


   customFunc(e)
   {
     this.myArray=this.doSth(); <- err
   }

还有我的网格视图(我使用devExtreme):

代码语言:javascript
复制
<div class="card">
  <div class="card-body">
    <dx-data-grid
      id="feature-releases"
      [disabled]="isBusy"
      [dataSource]="gridDataSource"
      [showColumnLines]="true"
      [showRowLines]="true"
      [showBorders]="true"
      (onSelectionChanged) ="onSelectionChanged()"
      (onRowUpdating)="updateRow($event)"
      (onToolbarPreparing)="onToolbarPreparing($event)"
      [rowAlternationEnabled]="true">

      <dxo-selection
        mode="multiple"
        [allowSelectAll]="false"
        showCheckBoxesMode="always"
        >
      </dxo-selection>

      <dxo-editing mode="form" [allowUpdating]="true" [allowDeleting]="true" [useIcons]="true">
        <dxo-form onClick="customFunc($event)">
          <dxi-item itemType="group" caption="Info">
            <dxi-item dataField="position"></dxi-item>
            <dxi-item dataField="versionNumber"></dxi-item>
            <dxi-item dataField="name"></dxi-item>
            <dxi-item dataField="created"></dxi-item>
            <dxi-item dataField="updated"></dxi-item>
          </dxi-item>
          <dxi-item itemType="group" caption="Data">
            <dxi-item dataField="description"></dxi-item>
            <dxi-item dataField="notes" [label]="{ text: 'Update Message' }" editorType="dxTextArea" [editorOptions]="{ height: 170 }"></dxi-item>
          </dxi-item>
          <dxi-item caption="Editor">
              <app-feature-release-editor
                [selectedReleases] = "selectedReleases">
              </app-feature-release-editor>
            <app-feature-release-create (featureReleaseCreated)="onFeatureReleaseCreated($event)"></app-feature-release-create>
          </dxi-item>
    <dxi-column type="buttons">
        <dxi-button name="edit" [onClick] = "customFunc"></dxi-button>
        <!-- <dxi-button id="iD"  icon="trash"  [onClick]="remove"></dxi-button> -->
    </dxi-column>   
      </dxo-form>
      </dxo-editing>
   </div>
</div>

然后-在我点击编辑按钮事件被正确调用之后,但是我不能使用我的component.Nothing中的任何字段在函数中是“可见的”。我需要从事件(id和其他一些)中获取数据,并将其传递给集合。我该怎么做呢?这只是我的代码的一部分,所以语法或结束标记(如'<')可能是错误的--但这不是我问题的重点。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-01 01:27:51

您可能处于不同的作用域中。可以将组件的实例绑定到customFunc函数以访问类。

将以下内容添加到constructor

代码语言:javascript
复制
constructor() {
    this.customFunc = this.customFunc.bind(this);
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73167083

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档