2013-02-11 37 views
0

我已經設置了一個測試JRS和clientfilter的小腳本。我使用了在互聯網上可以找到的設置,但不起作用。我正嘗試使用clientFilter在JRS上執行客戶端提取。然而,JRS正在查詢後端而不是執行客戶端的提取。我粘貼下面的腳本,我希望你們中的一個能解釋爲什麼它不起作用。JSonRestStore和CLientfilter

感謝

<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <link rel="stylesheet" type="text/css" href="js/dojo-release-1.7.2/dojo/resources/dojo.css"/> 
    <link rel="stylesheet" type="text/css" href="js/dojo-release-1.7.2/dijit/themes/tundra/tundra.css"/> 

    <script> 
     dojoConfig= { 
      has: { 
       "dojo-firebug": true 
      }, 
      parseOnLoad: true, 
      isDebug: true, 
      locale: "nl" 
     }; 
    </script> 

    <script type="text/javascript" src="js/dojo-release-1.7.2/dojo/dojo.js"></script> 

    <script type="text/javascript"> 
     dojo.require("dojox.data.ClientFilter"); 
     dojo.require("dojox.data.JsonRestStore"); 
     dojo.require("dijit.form.Button"); 

     myStore = new dojox.data.JsonRestStore({target:"TARGET"}); 
     myStore.fetch(); 

     dojo.ready(function() { 
      dojo.connect(dijit.byId("query"), "onClick", function() { 
       myStore.fetch({query:{id:"4"},queryOptions:{cache:true}, onItem: function(item) {console.log(item); }}); 
      }); 
     }); 
    </script> 
</head> 

<body cllass="tundra"> 
    <button type="button" id="query" data-dojo-type="dijit.form.Button">Query</button> 
</body> 

回答

0

我做了一個的jsfiddle,顯示瞭如何用新的語法和道場商店做到這一點。 http://jsfiddle.net/SgyYW/

require([ 
"dojo/store/Cache", 
"dojo/store/JsonRest", 
"dojo/store/Memory", 
"dojo/parser", 
"dojo/on", 
"dojo/ready", 
"dijit/form/Button", 
"dijit/registry" 
],function(Cache,JsonRest,Memory,parser,on,ready,Button,registry){ 
console.log('x'); 
var someData = [ 
    {id:1, name:"One"}, 
    {id:2, name:"Two"}, 
    {id:3, name:"Three"}, 
    {id:4, name:"Four"}, 
    {id:5, name:"Five"} 
]; 
recToQuery = 4; 
// recToQuery = 6; // try one that is not in the cache 
var memoryStore = new Memory({data: someData}); 
var restStore = new JsonRest({ target: "/i/dont/exist.json/"}); 
var myStore = new Cache(restStore, memoryStore); 
myStore.query({}); // this will ask for everything and prime the cache 
ready(function(){ 
    parser.parse(); 
    var queryBtn = registry.byId("query"); 
    console.log('queryBtn',queryBtn); 
    on(queryBtn, "click", function() { 
     console.log('query button clicked',[this,arguments]); 
     var resultOrPromise = myStore.get(recToQuery); 
     if (typeof resultOrPromise.then ==='function'){ 
      // it is asking the server 
      resultOrPromise.then(function(){ 
       console.log('Result from server fetch',arguments); 
      },function(){ 
       console.log('it queried the server but failed',arguments); 
      }); 
     }else{ 
      // it is in the cache (from the first query) 
      console.log('result from cache:',resultOrPromise); 
     } 
    });//end connect 
}); //end ready 
}); //end require 
+0

感謝,幾個問題,爲什麼你使用的新的語法,這是由於與舊的語法一些已知的bug?商店本身與我使用的不同,jsonreststore和reststore不同,現在我不能切換,因爲再造的數量太多會造成:( – Remco 2013-02-14 16:30:03

+0

你可以一起使用它們來緩解你的過渡痛苦。 2.0,對舊語法的支持將會被刪除,在我工作的地方,我們仍然有很多使用舊部件的小部件,舊部件可以使用新部件,新部件可以使用舊部件。 – Remento 2013-02-16 02:04:46

相關問題