0

我已经设置了一个小脚本来测试 JRS 和一个客户端过滤器。我已经使用我在互联网上可以找到的东西来设置它,但它不起作用。我正在尝试使用 clientFilter 在 JRS 上执行客户端提取。尽管如此,JRS 正在查询后端,而不是在客户端执行 fetch。我在下面粘贴了脚本,希望你们中的一个人能解释一下为什么它不起作用。

谢谢

<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>

4

1 回答 1

0

我制作了一个 jsfiddle,展示了如何使用新语法和 dojo 存储来做到这一点。 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
于 2013-02-12T04:46:51.727 回答