在州的另一个对象的状态引用中反映对象属性

时间:2018-05-21 08:41:22

标签: javascript reactjs react-redux

我是新手做出反应,我希望能够做到这一点。我的页面中有网格,它显示数组中的一些数据。我希望在我的状态中定义多个对象,如下所示。

take中的skipquery属性必须由pagingOptions

设置

filter中的query内的filter必须由Uncaught TypeError: Cannot read property 'filter' of undefined对象设置

现在它给我一个错误:this.state = { // filter for my grid view filter: { id: 1, status: "" etc.... }, // paging options for grid pagingOptions:{ pageSize: 5, skip: 0 }, //this represents query which is send to my api query:{ collectionName: "", filter: this.state.filter // here it throws an error: Cannot read property 'filter' of undefined sort: {}, projection: {}, take: this.state.pagingOptions.pageSize, // it will throw error also here since its same approach as filter skip: this.state.pagingOptions.skip // it will throw error also here since its same approach as filter includeTotalCount: true, context: null, } };

如何将这些属性设置为其值?

具有这些状态的我的组件如下所示:

Option Explicit
Public Sub TEST()

    Dim my_Array()
    my_Array = [A1].CurrentRegion.Value

    AutoRange my_Array

End Sub

Public Sub AutoRange(ByVal my_Array As Variant)

    Dim nb_rows As Long, nb_cols As Long
    Dim current_cell As Range

    nb_rows = UBound(my_Array, 1)
    nb_cols = UBound(my_Array, 2)

    Set current_cell = Selection

    current_cell.Resize(nb_rows, nb_cols).FormulaArray = current_cell.Formula

End Sub

1 个答案:

答案 0 :(得分:1)

您试图在this.state有值this.state之前引用undefined的属性,因此会出现您提到的错误消息。

要解决此问题,您可以在定义后将query属性添加到状态对象:

this.state = {
  // ...
};

this.state.query = {
  // ...
};