2012-08-27 45 views
1

我找不到這個地方,我不知道爲什麼跨域REST請求沒有被dojo解決。無論如何是這樣的問題:使用JSONP將WCF跨域使用存儲在數據網格中並查看數據dojo?

我正在實施dojo數據網格,我試圖從WCF不在我的域中獲取網格的數據,所以我crossdomain問題引發,我試圖通過使用JSONP來解決這個問題。

但我是道場的新手,所以我可能做錯了什麼。這裏是我的代碼:

require([ 
     "dojo/store/JsonRest", 
     "dojo/store/Memory", 
     "dojo/store/Cache", 
     "dojox/grid/DataGrid", 
     "dojo/data/ObjectStore", 
     "dojo/query", 
     "dijit/form/Button", 
     "dojo/domReady!", 
     "dojo/request/script","dojo/dom-construct" 
    ],function(script, domConstruct){ 

    //make the request just as before 
    script.get("http://localhost:8060/ListService.svc/LoadLists?uid=c4446476-15e6-e111-9ecb-b7c5971d170a", { 
    jsonp: "callback", 
    query: {q: "#dojo"} 
    }).then(function(data){ 
     test = data;   
    }).then(function(){ 
    console.log(results); 
    }); 
}, function (JsonRest, Memory, Cache, DataGrid, ObjectStore ,query) { 

     grid = new DataGrid({ 
      store: dataStore = test, 

      structure: [ 
       { name: "Blog Id", field: "id", width: "50px", }, 
       { name: "Name", field: "listtype", width: "200px",classes:"Name" }, 
       { name: "Phone Number", field: "longlevel", width: "200px",classes:"test" } 
      ] 
     }, "gridTest"); // make sure you have a target HTML element with this id 

     grid.startup(); 

     dojo.query("body").addClass("claro"); 

     grid.canSort = function() { return false; }; 


    }); 

我得到的錯誤是查詢不是一個函數。任何想法如何正確實施。

回答

0

簡單的錯誤只是把數據網格命令第一內側然後將數據返回

require([ 
     "dojo/store/JsonRest", 
     "dojo/store/Memory", 
     "dojo/store/Cache", 
     "dojox/grid/DataGrid", 
     "dojo/data/ObjectStore", 
     "dojo/query", 
     "dijit/form/Button", 
     "dojo/domReady!", 
     "dojo/request/script","dojo/dom-construct" 
    ],function(script, domConstruct){ 

    //make the request just as before 
    script.get("http://localhost:8060/ListService.svc/LoadLists?uid=c4446476-15e6-e111-9ecb-b7c5971d170a", { 
    jsonp: "callback", 
    query: {q: "#dojo"} 
    }).then(function(data){ 
     function (JsonRest, Memory, Cache, DataGrid, ObjectStore ,query) { 

     grid = new DataGrid({ 
      store: dataStore = test, 

      structure: [ 
       { name: "Blog Id", field: "id", width: "50px", }, 
       { name: "Name", field: "listtype", width: "200px",classes:"Name" }, 
       { name: "Phone Number", field: "longlevel", width: "200px",classes:"test" } 
      ] 
     }, "gridTest"); // make sure you have a target HTML element with this id 

     grid.startup(); 

     dojo.query("body").addClass("claro"); 

     grid.canSort = function() { return false; }; 


    })   
    }).then(function(){ 
    console.log(results); 
    }); 
}; 

如果你仍然可能會發現一個問題,因爲在創建網格請求從WCF返回之前。

如果發生了這種情況,請使用Dojo 1.8中的Deferred,這可以讓你控制你的進程序列。

所以你可以調用請求給它一些時間,然後把數據放到網格中去查看。

相關問題