我有一个绑定到cfc的网格,填充了id列和checkbox(boolean)列。 onLoad,我想得到一个ID值列表,但只有那些具有checkbox = 1的ID值 这是工作代码,得到了Jan S的大力帮助
<script language="JavaScript">
function init(){
var grid = ColdFusion.Grid.getGridObject('testgrid');
var gs = grid.getStore();
var records = gs.getRange();
var filteredRecords = [];
for (i = 0; i < records.length; i++) {
// note: for CF, you MUST capitalize grid header names
if (records[i].get('SELECT') === 1) {
var thisID = records[i].get('ID');
filteredRecords.push(thisID);
}
}
document.getElementById('idList').value=filteredRecords;
}
ColdFusion.Event.registerOnLoad(init,null,false,true);
</script>
<cfset items=QueryNew("id,Description,Select")>
<cfset Temp=QueryAddRow(items,1)>
<cfset Temp=QuerySetCell(items,"id","11")>
<cfset Temp=QuerySetCell(items,"Description","Some item")>
<cfset Temp=QuerySetCell(items,"Select",1)>
<cfset Temp=QueryAddRow(items)>
<cfset Temp=QuerySetCell(items,"id","22")>
<cfset Temp=QuerySetCell(items,"Description","Some other item")>
<cfset Temp=QuerySetCell(items,"Select",1)>
<cfset Temp=QueryAddRow(items)>
<cfset Temp=QuerySetCell(items,"id","33")>
<cfset Temp=QuerySetCell(items,"Description","A third item")>
<cfset Temp=QuerySetCell(items,"Select",0)>
<cfform>
<cfgrid name="testgrid" format="html" query="items">
<cfgridcolumn name="id" header="ID" select="no">
<cfgridcolumn name="Description" header="Description" select="no">
<cfgridcolumn name = "Select" header="Select" select="yes" type="boolean">
</cfgrid>
<br>
<!--- populate this with list of ID's having the checkbox checked, here: 11,22 --->
<input type="text" name="idList" id="idList"> <input type="button" name="getList" value="Get List" onClick="init()">
</cfform>
基本上我需要将这个SQL语句翻译成AJAX:
select stringColumn where booleanColumn = 1 from myGrid
我正在使用Cold Fusion 9,它基于js ext 3.1我相信
答案 0 :(得分:0)
从另一个字段为1的所有记录中获取包含所有字段的数组:
isData.on('load', function(store, records){
// create a new array with all records where the 'booleanColumn' is = 1
var filteredRecords = [];
for (i = 0; i < records.length; i++) {
if (records[i].get('booleanColumn') === 1) {
filteredRecords.push(records[i]);
}
}
console.log(filteredRecords);
// create a new array of 'stringColumn' values
var filteredValues = [];
for (i = 0; i < filteredRecords.length; i++) {
filteredValues[i] = filteredRecords[i].get('stringColumn');
}
console.log(filteredValues);
// proceed with filtered values...
});