如何通过网格分组获取所有ID?

发布于 2025-01-12 12:23:33 字数 1641 浏览 0 评论 0原文

我有一个 Kendo UI 网格,由对 api 的 Ajax 查询填充。 该网格具有用于示例 ID、状态(如果文档已生成或未生成)的列以及用于生成文档的按钮(如果尚未生成)。

我正在实现一个按钮来一次性为所有样本 ID 生成文档,并且需要获取剩余样本的 ID。

我根据状态对 ID 进行分组,如下所示:

dataSource.fetch(function(){
                          var view = dataSource.view();
                          console.log(view.length);
                          console.log(view[0]);
                    });

我想实现一个函数来获取所有 ID(状态为 'F' )并为它们生成文档。如何在函数中获取此视图数组?

我尝试了这个,但它说数据源未定义。

<button id='RegenerateButton' onclick=regenerateAll()>Regenerate All</button>

function regenerateAll(){
                dataSource.fetch(function(){
                          var view = dataSource.view();
                         console.log(view.length);
                          console.log(view[0]);
                    });
            }

我的数据源定义如下:

$(document).ready(function () {
                var crudServiceBaseUrl = window.location.origin + "/api",
                    dataSource = new kendo.data.DataSource
                    ({
                        type: "json",
                        serverPaging: true,
                        serverSorting: true,
                        serverFiltering: true,
                        allowUnsort: true,
                        pageSize: 10,
                        group:{field:"Status"},
                        transport: {
                            read: {
                                url: crudServiceBaseUrl + "/HL7Message/getListOfProcessedData/",
                                dataType: "json",
            
.....

I have a Kendo UI grid that is populated by Ajax query to an api.
The grid has column for sample IDs, status (if document is generated or not) and a button to generate the document (if not already).

I am implementing a button to generate documents for all sampleIds in one go and need to fetch the IDs of remaining ones.

And I group the IDs based on status like this:

dataSource.fetch(function(){
                          var view = dataSource.view();
                          console.log(view.length);
                          console.log(view[0]);
                    });

I want to implement a function that gets all the IDs (with status 'F' ) and generate documents for them. How do I get this view array in the function?

I tried this but it says datasource is undefined.

<button id='RegenerateButton' onclick=regenerateAll()>Regenerate All</button>

function regenerateAll(){
                dataSource.fetch(function(){
                          var view = dataSource.view();
                         console.log(view.length);
                          console.log(view[0]);
                    });
            }

My dataSource is defined like this:

$(document).ready(function () {
                var crudServiceBaseUrl = window.location.origin + "/api",
                    dataSource = new kendo.data.DataSource
                    ({
                        type: "json",
                        serverPaging: true,
                        serverSorting: true,
                        serverFiltering: true,
                        allowUnsort: true,
                        pageSize: 10,
                        group:{field:"Status"},
                        transport: {
                            read: {
                                url: crudServiceBaseUrl + "/HL7Message/getListOfProcessedData/",
                                dataType: "json",
            
.....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫性小仙女 2025-01-19 12:23:33

您要做的第一个更改是获取数据源的数据 (文档)而不是视图。

在对数据进行分组方面,您需要执行以下操作:

  1. 获取数据
  2. 按状态字段过滤数据
  3. 映射数据以获取其 id 字段
  4. 仅从映射/过滤的值中获取唯一值

const everyId = dataSource.data()
                  .filter(row => row.Status === 'F')
                  .map(row => row.Id);
const uniqueIds = [...new Set(everyId)];

以下是一个示例 由于数据源变量未定义,我需要查看更多代码。我能想到两种可能性:

  1. 您有一个拼写错误,并且数据源变量被命名为其他名称
  2. 数据源位于与您尝试访问它的位置不同的上下文(即范围)中

The first change you will want to make is to get the data source's data (documentation) and not the view.

In terms of grouping the data you will need to do the following:

  1. Get the data
  2. Filter the data by its status field
  3. Map the data to get its id field
  4. Get just the unique values from the mapped/filtered values

Here is an example:

const everyId = dataSource.data()
                  .filter(row => row.Status === 'F')
                  .map(row => row.Id);
const uniqueIds = [...new Set(everyId)];

In terms of the datasource variable being undefined, I will need to see a bit more code. There are two possibilities I can think of:

  1. You have a typo and the datasource variable is named something else
  2. The datasource lives in a different context (i.e. scope) than where you're trying to access it from
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文