有人知道如何从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想要的匹配。oData。
{
"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
}
]
}为了具体回答利的问题,我尝试将查询转换为一个结构数组,然后序列化它。这给了我这个,这又是错误的‘形状’。
[
{
"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
}
]回答朱尔斯,jsGrid我的朋友,而不是cfgrid :-)
发布于 2017-02-01 17:10:02
我也遇到了一些问题,最终不得不构建自己的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>https://stackoverflow.com/questions/41981322
复制相似问题