2014-02-13 51 views
0

道歉,如果我還沒有找到它的文檔但在...queryformat和Railo

問:如何更改爲Railo Ajax調用的queryformat? 這裏是我的組件:

component { 

    remote function Read() returnformat='json' { 
     svc = new Query(); 
     svc.setSQL("SELECT * FROM INFORMATION_SCHEMA.TABLES"); 
     obj = svc.execute(); 
     local.result.Prefix = obj.getPrefix(); 
     local.result.qry = obj.getResult(); 
     url.queryFormat = "column"; 
     return local.result; 
    } 
    } 

,這裏是我的JavaScript:

(function() { 
    var local = {}; 

    local.type = 'POST'; 
    local.url = 'AJAX.cfc'; 
    local.dataType = 'json'; 
    local.data = {}; 
    local.data.method = 'Read'; 
    local.Promise = $.ajax(local); 
    local.Promise.done(done); 
    local.Promise.fail(fail); 

    function done(response) { 
     console.log(response); 
     debugger; 
    } 
    function fail(xhr,status,response) { 
     debugger; 
    } 
})(); 

什麼我得到的回覆是:

response.qry.DATA[] // 57 arrays, each of length 4 

但ColdFusion的返回這一點,我已經越來越喜歡使用的(能夠使用的列名,而不是在陣列位置):

response.qry.DATA.TABLE_CATALOG[] // An array of 57 elements 
response.qry.DATA.TABLE_SCHEMA[] 
response.qry.DATA.TABLE_NAME[] 
response.qry.DATA.TABLE_TYPE[] 

回答

3

使用ReturnFormat =「普通」的功能,併爲serializeJson()的第二個參數傳遞true

serializeJson(Query, true) 

這會給你由列序列化JSON對象,所以你可以只返回它。

+0

謝謝lgal!我會檢查出來的! –