简体   繁体   English

使用CORS使用ASP.NET Core WebAPI数据源填充jqwidgets dataAdapter

[英]Filling jqwidgets dataAdapter with asp.net core webapi datasource using CORS

I'm trying to fill the jqx.dataAdapter from a asp.net core webapi project using CORS and am able to see the data pass back across to the JQWidgets project until I try to fill the DataAdapter. 我正在尝试使用CORS从asp.net核心webapi项目填充jqx.dataAdapter,并且能够看到数据传递回JQWidgets项目,直到尝试填充DataAdapter。 The jqx.dataAdapter.records does not fill however the jqx.dataAdapter.recordids will fill with the 8 expected rows. jqx.dataAdapter.records不会填充,但是jqx.dataAdapter.recordids将填充8个预期行。

WebAPI project: WebAPI项目:

// GET api/changelog
[HttpGet]
public JsonResult Get()
{
    IEnumerable<ApplicationChangeEntryExtension> results = null;
    try
    {
       results = (from x in db.tblApplicationChangeLogEntries
                  select new ApplicationChangeEntryExtension()
                  {
                      ID = x.ID,
                      Application = x.Application,
                      Version = x.Version,
                      ReleaseCandidate = x.ReleaseCandidate,
                      IsReleaseCandidate = x.IsReleaseCandidate,
                      CustomerContent = x.CustomerContent,
                      InternalContent = x.InternalContent,
                      DevDate = x.DevDate,
                      TestDate = x.TestDate,
                      PreReleaseDate = x.PreReleaseDate,
                      PreProductionDate = x.PreProductionDate,
                      DeployDate = x.DeployDate
                  });
    }
    catch(Exception exc)
    {
        Console.WriteLine(exc);
    }
    return Json(results);
}

jqwidgets project: jqwidgets项目:

$('#ChangeLogLink').on('click', function (event) {
    $('#popupwindowChangeLog').jqxWindow({
        showCollapseButton: false,
        showCloseButton: true,
        draggable: false,
        isModal: true,
        autoOpen: false,
        height: 500,
        width: 850,
        theme: _Theme,
        modalOpacity: 0,
        initContent: function () {
            var _source = {
                type: 'GET',
                datatype: 'json',
                root: 'results',
                datafields: [
                    { name: 'ID', type: 'integer' },
                    { name: 'Application', type: 'string' },
                    { name: 'Version', type: 'string' },
                    { name: 'ReleaseCandidate', type: 'integer' },
                    { name: 'IsReleaseCandidate', type: 'boolean' },
                    { name: 'CustomerContent', type: 'string' },
                    { name: 'InternalContent', type: 'string' },
                    { name: 'DevDate', type: 'date' },
                    { name: 'TestDate', type: 'date' },
                    { name: 'PreReleaseDate', type: 'date' },
                    { name: 'PreProductionDate', type: 'date' },
                    { name: 'DeployDate', type: 'date' }
                ],
                url: 'http://localhost:2512/api/changelog',
                id: 'ID'
            };

            var _dataAdapter = new $.jqx.dataAdapter(_source);

            $("#divChangeLogListContainer").html('<div id="divChangeLogList"></div>');
            $("#divChangeLogList").jqxDataTable({
                source: _dataAdapter,
                width: '100%',
                height: '100%',
                theme: _integronTheme,
                pageable: true,
                pagerButtonsCount: 5,
                sortable: true,
                filterable: false,
                columnsResize: true,
                pageSize: 25,
                altRows: true,
                columns: [
                    { text: 'ID', datafield: 'ID'},
                    { text: 'Application', datafield: 'Application'},
                    { text: 'Version', datafield: 'Version'},
                    { text: 'Release Candidate', datafield: 'ReleaseCandidate'},
                    { text: 'Is Release Candidate', datafield: 'IsReleaseCandidate'},
                    { text: 'Customer Content', datafield: 'CustomerContent'},
                    { text: 'Internal Content', datafield: 'InternalContent'},
                    { text: 'Customer Order #', datafield: 'CustomerOrderID'},
                    { text: 'Dev Date', datafield: 'DevDate', cellsformat: 'M/d/yyyy', cellsalign: 'center', align: 'center'},
                    { text: 'Test Date', datafield: 'TestDate', cellsformat: 'M/d/yyyy', cellsalign: 'center', align: 'center'},
                    { text: 'PreRelease Date', datafield: 'PreReleaseDate', cellsformat: 'M/d/yyyy', cellsalign: 'center', align: 'center'},
                    { text: 'PreProduction Date', datafield: 'PreProductionDate', cellsformat: 'M/d/yyyy', cellsalign: 'center', align: 'center'},
                    { text: 'Deploy Date', datafield: 'DeployDate', cellsformat: 'M/d/yyyy', cellsalign: 'center', align: 'center'}
                ]
            });
        }
    });
    $('#popupwindowChangeLog').jqxWindow('open');

});

I think you miss the autoBind parameter when creating the data adapter, or calling its dataBind() method. 我认为您在创建数据适配器或调用其dataBind()方法时会错过autoBind参数。

Alternatively you can also create the data table using asynchronous loading. 或者,您也可以使用异步加载来创建数据表。

See examples for each method at jqwidgets.com jqwidgets.com上查看每种方法的示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM