当数据库没有返回数据时

发布于 2024-10-09 15:02:43 字数 154 浏览 5 评论 0原文

我在 init 方法中启动一个加载面板并将其隐藏在 ReturnDataPayload 事件中。当数据表中有一些值时,这是完美的工作。但是当没有从数据库返回数据时,控件不会返回 DataPayLoad 事件。请帮助我找到一个即使响应没有任何数据也会触发的事件,或者告诉我一种隐藏加载面板的方法。

I am intiating a loading panel in init method and hiding it in ReturnDataPayload event.This is working perfectly when data Table has got some values in it.But when there is no data returned from database , the control is not going to returnDataPayLoad event.Please help me in finding an event which will be fired even when the response doesn't have any data or tell me a way to hide the loading panel.

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

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

发布评论

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

评论(1

旧情勿念 2024-10-16 15:02:43

如果您想要自定义行为,请使用 dataTable 的 dataSource 的 DataSource 的 sendRequest 方法

(function() {
    var YdataTable  = YAHOO.widget.DataTable,
        YdataSource = YAHOO.util.DataSource;

    var settings = {
        container:"<DATATABLE_CONTAINER_GOES_HERE>",
        source:"<URL_TO_RETRIEVE_YOUR_DATA>",
        columnSettings:[
            {key:"id", label:"Id"}
        ],
        dataSourceSettings:{
            responseType:YdataSource.TYPE_JSON,
            responseSchema:{
                resultsList:"rs",
                fields:[
                    {key:"id"}
                ]
            }
        },
        dataTableSettings:{
            initialLoad:false
        }
    }

    var dataTable = new YdataTable(
                    settings.container, 
                    settings.columnSettings, 
                    new YdataSource(
                    settings.source, 
                    settings.dataSourceSettings), 
                    settings.dataTableSettings);
})();

记住无论您的数据来自哪个来源:XML、JSON、JavaScript 对象、TEXT,您始终都会获得数据以统一的方式通过DataSource的sendRequest方法。因此,当您想要检索数据并同时添加自定义行为时,请使用它

dataTable.getDataSource().sendRequest(null, {
    success:function(request, response, payload) {
        if(response.results.length == 0) {
            // No data returned
            // Do what you want right here
            // You can, for instance, hide the dataTable by calling this.setStyle("display", "none");
        } else {
            // Some data returned
            // If you want to use default the DataTable behavior, just call

            this.onDataReturnInitializeTable(request, response, payload);
        }
    },
    scope:dataTable,
    argument:dataTable.getState()
});

响应的属性是

  • results (Array):统一方式的数据源。 对于结果数组中的每个对象,根据responseSchema 的 fields 属性,一个属性。请注意,我使用response.results.length来验证是否已返回某些数据
  • 错误(布尔值):指示数据错误
  • 缓存(布尔值):指示缓存的响应
  • 元(对象):模式解析的元数据

打开YUI dataTable 页面,查找在运行时加载数据即可查看YUI dataTable 提供的一些内置函数

我希望它能有用,如果您想了解有关 YUI 的任何其他信息,请随时寻求帮助。查看演示页面,了解 YUI dataTable 的优秀功能

If you want a custom behavior, use DataSource's sendRequest method of the dataTable's dataSource

(function() {
    var YdataTable  = YAHOO.widget.DataTable,
        YdataSource = YAHOO.util.DataSource;

    var settings = {
        container:"<DATATABLE_CONTAINER_GOES_HERE>",
        source:"<URL_TO_RETRIEVE_YOUR_DATA>",
        columnSettings:[
            {key:"id", label:"Id"}
        ],
        dataSourceSettings:{
            responseType:YdataSource.TYPE_JSON,
            responseSchema:{
                resultsList:"rs",
                fields:[
                    {key:"id"}
                ]
            }
        },
        dataTableSettings:{
            initialLoad:false
        }
    }

    var dataTable = new YdataTable(
                    settings.container, 
                    settings.columnSettings, 
                    new YdataSource(
                    settings.source, 
                    settings.dataSourceSettings), 
                    settings.dataTableSettings);
})();

keep in mind No matter which source is your data: XML, JSON, JavaScript object, TEXT, you always will get your data in a unified way through DataSource's sendRequest method. So when you want to retrieve your data and, at the same time, add custom behavior, use it

dataTable.getDataSource().sendRequest(null, {
    success:function(request, response, payload) {
        if(response.results.length == 0) {
            // No data returned
            // Do what you want right here
            // You can, for instance, hide the dataTable by calling this.setStyle("display", "none");
        } else {
            // Some data returned
            // If you want to use default the DataTable behavior, just call

            this.onDataReturnInitializeTable(request, response, payload);
        }
    },
    scope:dataTable,
    argument:dataTable.getState()
});

The properties of the response are

  • results (Array): Your source of data in a unified way. For each object in the results Array, There is a property according to responseSchema's fields property. Notice i use response.results.length to verify if some data has been returned
  • error (Boolean): Indicates data error
  • cached (Boolean): Indicates cached response
  • meta (Object): Schema-parsed meta data

On the YUI dataTable page, look for Loading data at runtime to see some built-in functions provided by YUI dataTable

I hope it can be useful and feel free to ask for help for anything else you want about YUI. See a demo page of nice features of YUI dataTable

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文