1

これはどこにも見つからず、クロスドメイン REST リクエストが dojo によって解決されない理由がわかりません。とにかくここに問題があります:

Dojo data-grid を実装しており、自分のドメインにない WCF からグリッドのデータを取得しようとしているため、クロスドメインの問題が発生し、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; };


     });

私が得ているエラーは、クエリは関数ではありません。これを正しく実装する方法についてのアイデア。

4

1 に答える 1

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 を使用して、プロセス シーケンスを制御してください。

そのため、リクエストを呼び出してしばらく待ってから、データをグリッドに配置して表示することができます。

于 2012-09-02T17:47:28.217 に答える