我已设置CFGrid
,显示记录列表,并且需要能够删除所选记录。但是,我收到以下错误:"错误:该属性的值' deleteAssignment'是null或未定义,而不是Function对象"。从我所见过的,其他人的设置函数非常相似,没有抛出该错误。我的代码在
CFGrid代码:
<cfform height="200" id="empGridForm" name="empGridForm">
<cfgrid name="employeePerspective" format="html" striperows="yes"
delete="yes" query="qEmployeeAssignments" height="200" selectmode="row">
<cfgridcolumn name="employeeName" header="Last Name" width="200"/>
<cfgridcolumn name="reportName" header="Report Name" width="200" />
<cfgridcolumn name="reportDescrip" header="Report Description"
width="300"/>
</cfgrid>
<cfinput type="button" name="newEmp" label="Add Employee" value="Add
Employee" id="addEmployeebtn">
<cfinput type="button" name="DeleteEmp" label="Delete Employee"
value="Delete
Employee" id="deleteEmployeebtn" onClick="deleteAssignment();">
</cfform>
用于删除所选数据网格行的Javascript:
<cfajaxproxy cfc="deleteFunc" jsclassname="Users">
<script language="javascript">
function deleteAssignment() { <!---javascript delete function to remove selected employee from assigment--->
var selectedRecord = employeePerspective.getSelections(); <!--- This variable 'selectedRecord' is set to the datagrid selected value --->
var employeeName = selectedRecord[0].data.employeeName; <!---This deleteRecord variable is set to the datagrid selected value stored in variable selectedRecord--->
if(confirm('Delete Employee: ' + selectedRecord[0].data.employeeName)) <!--- This generates a confirmation window. When confirmed variable deleteRecord passed to CFC delete function--->
{
objeUser.delUser(employeeName); <!---This line passes deleteRecord variable into CFC method and executes delete method--->
};
}
var objUser = new Users(); <!--- This line sets a JS variable equal to a Coldfusion function located in coldfusionFunction.cfc file--->
objUser.setErrorHandler(showError); <!--- This line sets an error handling method --->
objectUser.setCallbackHandler(handleResult); <!--- This line sets callback method which will refresh the grid --->
function handleResult(res) { <!---This line sets the event handler which will refresh the grid upon execution of delete function --->
Coldfusion.Grid.refresh('employeePerspective',false);
}
function showError() <!--- This is the error handling function. Called when the delete function is unsuccessful --->
{
alert("Your attempt to delete the selected record was unsuccessful. Try again or contact administrator");
</script>
JavaScript函数是使用cfajaxproxy
将数据网格值传递到CFC,其中函数将运行cfquery
以完成删除,然后JavaScript刷新网格而不刷新页面。