【问题标题】:primevue fill datatable with protobufprimevue 使用 protobuf 填充数据表
【发布时间】:2021-07-02 19:00:22
【问题描述】:

我从服务器获取 google protobuf 格式的数据。
但无法理解如何填充 Primevue 数据表列。
这是我的示例代码:

<template>
  <Card>
    <template #content>
      <DataTable
        :value="statisticList"
        :paginator="true"
        :rows="10"
        :rowsPerPageOptions="[10, 20, 50]"
        class="p-datatable-sm"
        paginatorTemplate="CurrentPageReport FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink RowsPerPageDropdown"
        responsiveLayout="scroll"
        stripedRows
        showGridlines
      >
        <Column field="getId()" header="Id" :sortable="true"></Column>
        <Column field="getSymbol()" header="Symbol"></Column>
        <template #paginatorLeft>
          <Button
            type="button"
            icon="pi pi-refresh"
            class="p-button-text"
            @click="getStatistics"
          />
        </template>
      </DataTable>
    </template>
  </Card>
</template>

<script>
import { statisticSubject } from "../../services/SubjectService";
import { requestStatistic } from "../../services/WebsocketService";
export default {
  data() {
    return {
      statisticList: null,
    };
  },
  created() {
    requestStatistic();
    statisticSubject.subscribe((e) => (this.statisticList = e));
  },
  methods: {
    getStatistics() {
      requestStatistic();
    },
  },
};
</script>   

这是我的 protobuf 结构的一部分:

syntax = "proto3";
message StatisticBuffer {
  int64 id = 1;
  string symbol = 2;
  string exchange = 3;
}

注意:
数据获取和加载没有任何问题购买primevue不会填满列。

如何解决这个问题?

【问题讨论】:

    标签: javascript vue.js vuejs3 primevue


    【解决方案1】:

    已修复
    将代码更改为:

    statisticSubject.subscribe((e) => {
          for (let i = 0; i < e.length; i++) {
            this.statisticList[i] = e[i].toObject();
          }
    });
    

    【讨论】:

      猜你喜欢
      • 2013-08-29
      • 1970-01-01
      • 2018-12-27
      • 2013-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多