0

有谁知道如何编组来自 ColdFusion 查询的数据,以便 jsGrid 可以使用它?

目前,我使用 serializeJSON() 将查询结果转换为 json,然后尝试将其提供给 jsGrid。我正在使用的 jsGrid 示例是此页面上的 oData 示例:http: //js-grid.com/demos/

我看到的问题是,由 serializeJSON() 生成的 json 数据包与演示所需的 oData 数据包的“形状”不同。

所以,问题是,如何将我的数据从 ColdFusion 编组为 oData 格式?


更新:在回答一些问题时,这是 serializeJSON() 产生的:

{
  "COLUMNS": [
    "ROLE_KY",
    "ROLE_NAME",
    "ROLE_TEXT",
    "ROLE_RANKING",
    "ROLE_STATUS",
    "ROLE_DATE_CREATED",
    "ROLE_DATE_AMENDED"
  ],
  "DATA": [
    [
      1,
      "Developer",
      "Like Admin. Plus access to diagnostic info hidden to other users",
      1,
      1,
      "November, 29 2016 20:35:48",
      null
    ],
    [
      2,
      "Admin",
      "Like Contributor, but can also edit users, ie. full access",
      2,
      1,
      "November, 29 2016 20:35:48",
      null
    ],
    [
      3,
      "Contributor",
      "Like Privieged, but can also edit data, but not users",
      3,
      1,
      "January, 20 2017 14:51:39",
      null
    ],
    [
      4,
      "Privileged",
      "Like Basic, but can also read restricted data",
      4,
      1,
      "November, 29 2016 20:35:48",
      null
    ],
    [
      5,
      "Basic",
      "Basic users can use the search facilities and read non-restricted data only",
      5,
      1,
      "November, 29 2016 20:35:48",
      null
    ]
  ]
}

以下是 jsGrid/oData 演示页面生成的内容。serializeJSON() 中有一些非默认选项以不同的格式(行、列、结构)生成数据包,但它们都不符合 jsGrid 的要求,即。o数据。

{
  "odata.metadata": "http://services.odata.org/V3/(S(3mnweai3qldmghnzfshavfok))/OData/OData.svc/$metadata#Products",
  "value": [
    {
      "ID": 0,
      "Name": "Bread",
      "Description": "Whole grain bread",
      "ReleaseDate": "1992-01-01T00:00:00",
      "DiscontinuedDate": null,
      "Rating": 4,
      "Price": 2.5
    },
    {
      "ID": 1,
      "Name": "Milk",
      "Description": "Low fat milk",
      "ReleaseDate": "1995-10-01T00:00:00",
      "DiscontinuedDate": null,
      "Rating": 3,
      "Price": 3.5
    },
    {
      "ID": 2,
      "Name": "Vint soda",
      "Description": "Americana Variety - Mix of 6 flavors",
      "ReleaseDate": "2000-10-01T00:00:00",
      "DiscontinuedDate": null,
      "Rating": 3,
      "Price": 20.9
    },
    {
      "ID": 3,
      "Name": "Havina Cola",
      "Description": "The Original Key Lime Cola",
      "ReleaseDate": "2005-10-01T00:00:00",
      "DiscontinuedDate": "2006-10-01T00:00:00",
      "Rating": 3,
      "Price": 19.9
    },
    {
      "ID": 4,
      "Name": "Fruit Punch",
      "Description": "Mango flavor, 8.3 Ounce Cans (Pack of 24)",
      "ReleaseDate": "2003-01-05T00:00:00",
      "DiscontinuedDate": null,
      "Rating": 3,
      "Price": 22.99
    },
    {
      "ID": 5,
      "Name": "Cranberry Juice",
      "Description": "16-Ounce Plastic Bottles (Pack of 12)",
      "ReleaseDate": "2006-08-04T00:00:00",
      "DiscontinuedDate": null,
      "Rating": 3,
      "Price": 22.8
    },
    {
      "ID": 6,
      "Name": "Pink Lemonade",
      "Description": "36 Ounce Cans (Pack of 3)",
      "ReleaseDate": "2006-11-05T00:00:00",
      "DiscontinuedDate": null,
      "Rating": 3,
      "Price": 18.8
    },
    {
      "ID": 7,
      "Name": "DVD Player",
      "Description": "1080P Upconversion DVD Player",
      "ReleaseDate": "2006-11-15T00:00:00",
      "DiscontinuedDate": null,
      "Rating": 5,
      "Price": 35.88
    },
    {
      "ID": 8,
      "Name": "LCD HDTV",
      "Description": "42 inch 1080p LCD with Built-in Blu-ray Disc Player",
      "ReleaseDate": "2008-05-08T00:00:00",
      "DiscontinuedDate": null,
      "Rating": 3,
      "Price": 1088.8
    },
    {
      "odata.type": "ODataDemo.FeaturedProduct",
      "ID": 9,
      "Name": "Lemonade",
      "Description": "Classic, refreshing lemonade (Single bottle)",
      "ReleaseDate": "1970-01-01T00:00:00",
      "DiscontinuedDate": null,
      "Rating": 7,
      "Price": 1.01
    },
    {
      "odata.type": "ODataDemo.FeaturedProduct",
      "ID": 10,
      "Name": "Coffee",
      "Description": "Bulk size can of instant coffee",
      "ReleaseDate": "1982-12-31T00:00:00",
      "DiscontinuedDate": null,
      "Rating": 1,
      "Price": 6.99
    }
  ]
}

在对 Leigh 问题的具体回答中,我尝试将查询转换为结构数组,然后将其序列化。这给了我这个,这又是错误的“形状”。

[
  {
    "ROLE_KY": 1,
    "ROLE_DATE_AMENDED": "",
    "ROLE_NAME": "Developer",
    "ROLE_TEXT": "Like Admin. Plus access to diagnostic info hidden to other users",
    "ROLE_DATE_CREATED": "November, 29 2016 20:35:48",
    "ROLE_STATUS": 1,
    "ROLE_RANKING": 1
  },
  {
    "ROLE_KY": 2,
    "ROLE_DATE_AMENDED": "",
    "ROLE_NAME": "Admin",
    "ROLE_TEXT": "Like Contributor, but can also edit users, ie. full access",
    "ROLE_DATE_CREATED": "November, 29 2016 20:35:48",
    "ROLE_STATUS": 1,
    "ROLE_RANKING": 2
  },
  {
    "ROLE_KY": 3,
    "ROLE_DATE_AMENDED": "",
    "ROLE_NAME": "Contributor",
    "ROLE_TEXT": "Like Privieged, but can also edit data, but not users",
    "ROLE_DATE_CREATED": "January, 20 2017 14:51:39",
    "ROLE_STATUS": 1,
    "ROLE_RANKING": 3
  },
  {
    "ROLE_KY": 4,
    "ROLE_DATE_AMENDED": "",
    "ROLE_NAME": "Privileged",
    "ROLE_TEXT": "Like Basic, but can also read restricted data",
    "ROLE_DATE_CREATED": "November, 29 2016 20:35:48",
    "ROLE_STATUS": 1,
    "ROLE_RANKING": 4
  },
  {
    "ROLE_KY": 5,
    "ROLE_DATE_AMENDED": "",
    "ROLE_NAME": "Basic",
    "ROLE_TEXT": "Basic users can use the search facilities and read non-restricted data only",
    "ROLE_DATE_CREATED": "November, 29 2016 20:35:48",
    "ROLE_STATUS": 1,
    "ROLE_RANKING": 5
  }
]

回答 Jules,我的朋友 jsGrid,而不是 cfgrid :-)

4

1 回答 1

0

我也遇到了问题,最后不得不建立自己的 json 数据集。

在parts.cfc 中:

<cfsavecontent variable="myOutput">{"QUERY":{"COLUMNS":["ID","BRANDID","CODE","ITEMNO","NAME","SIZE","UNIT","OUNCES","PRICE","DATETIME","USED"],"DATA":[<cfoutput query="parts" maxRows="#arguments.pageSize#">["#ID#","#BRANDID#","#CODE#","#ITEMNO#","#NAME#","#SIZE#","#UNIT#","#OUNCES#","#PRICE#","#datetime#",<cfif
        used gte 1>"Yes"<cfelse>"No"</cfif>]<cfif (currentRow neq recordCount) and (currentRow mod arguments.pageSize neq 0)>,</cfif></cfoutput>]},<cfoutput>"TOTALROWCOUNT":#result_count.totalRecords#}</cfoutput></cfsavecontent>
<cfreturn myOutput>

在调用模板中,parts.cfm:

<cfscript>
  args = {};
  // bind grid to structure returned by getParts method
  args.bind = "cfc:parts.getParts({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection},'#url.brandid#')";
  args.delete = FALSE;
  args.format = "html";
  args.insert = TRUE;
  args.name = "partsGrid";
  // bind onchange event to savePart method
  args.onchange = "cfc:parts.savePart({cfgridaction},{cfgridrow},{cfgridchanged},'#url.brandid#')";
  args.pagesize = "20";
  args.selectmode = "edit";
  args.striperows = TRUE;
  args.width= session.bodyWidth;
  //args.deleteButton = "[Delete]";
  //args.insertButton = "[Add]";
  args.onLoad = "initMore";
</cfscript>

<cfform name="partsGrid">
  <cfgrid attributecollection="#args#">
        <cfgridcolumn display="yes" headerMenu="no"  name="code"    />
        <cfgridcolumn display="yes" headerMenu="no"  name="itemNo"  />
        <cfgridcolumn display="yes" headerMenu="no"  name="name"    />
        <cfgridcolumn display="yes" headerMenu="no"  name="size"    />
        <cfgridcolumn display="yes" headerMenu="no"  name="unit"  values="L,ML,QT,GL,PT,OZ,HP,GR,TK"  />
        <cfgridcolumn display="yes" headerMenu="no"  name="ounces"  />
        <cfgridcolumn display="yes" headerMenu="no"  name="price"   />
        <cfgridcolumn display="yes" headerMenu="no"  name="datetime"   />
        <cfgridcolumn display="yes" headerMenu="no"  name="used"   />
        <cfgridcolumn display="no"  headerMenu="no"  select="yes" name="brandID" />
        <cfgridcolumn display="no"  headerMenu="no"  select="yes" name="id"       />
  </cfgrid>
</cfform>
于 2017-02-01T17:10:02.980 回答