如何从服务器端的 Kendo 模型中获取发布的字段值?我在服务器端有一个记录器。这表明我收到了所有字段,包括列名和值。但是,我不确定如何检索这些值:
使用的脚本:
<script>
$(document).ready(function () {
var crudServiceBaseUrl = "http://localhost:8500/test/test1.cfc?method=",
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: crudServiceBaseUrl+"JsonRead",
dataType: "json"
},
create: {
url: crudServiceBaseUrl+"JsonCreate",
dataType: "json"
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
return options;
}
},
batch: true,
pageSize: 20,
schema: {
type: "json",
model: {
id: "productid",
fields: {
productid: { editable: false, nullable: true },
productname: { validation: { required: true } },
unitprice: { type: "number", validation: { required: true, min: 1} },
discontinued: { type: "boolean" },
unitsinstock: { type: "number", validation: { min: 0, required: true } }
}
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
pageable: true,
height: 430,
toolbar: ["create"],
columns: [
"productname",
{ field: "unitprice", title: "Unit Price", format: "{0:c}", width: "100px" },
{ field: "unitsinstock", title:"Units In Stock", width: "100px" },
{ field: "discontinued", width: "100px" },
{ command: ["edit", "destroy"], title: " ", width: "172px" }],
editable: "inline"
});
});
</script>
测试1.cfc
<cfcomponent>
<cffunction name="init">
<cfreturn this>
</cffunction>
<cffunction name="JsonRead" returntype="any" description="Return all Product" access="remote">
<cfquery name="getallproducts" datasource="DataSource">
SELECT * from Products
</cfquery>
<cfset var aTmp = arraynew(1)>
<cfif getallproducts.recordcount>
<cfloop query="getallproducts">
<cfset stTmp = structNew()>
<cfloop list="#lcase(getallproducts.columnlist)#" index="col">
<cfset stTmp[col] = getallproducts[col][currentRow]>
</cfloop>
<cfset arrayAppend(aTmp,stTmp)>
</cfloop>
<cfelse>
<cfset stTmp = structNew()>
<cfloop list="#lcase(getallproducts.columnlist)#" index="col">
<cfset stTmp[col] = "">
</cfloop>
<cfset arrayAppend(aTmp,stTmp)>
</cfif>
<cfset ss=#SerializeJSON(aTmp)#>
<cfreturn ss>
</cffunction>
<cffunction name="JsonCreate" returntype="void" description="Create New Row" access="remote">
<cfargument name="models" type="string" required="yes">
<cfset data = urldecode(arguments.models)>
<cfset data = deserializeJSON(data, false)>
</cffunction>
</cfcomponent>