简体   繁体   English

使用config.json文件设置Dojox.app缓存的存储

[英]Setting up a Dojox.app cached store using config.json file

I'm trying to create a Dojox.app that reads data from a server once and then queries that data as needed during the lifetime of the app. 我正在尝试创建一个Dojox.app,它从服务器读取一次数据,然后在应用程序的生命周期内根据需要查询该数据。 A "dojo/store/JsonRest" will fetch the data and the "dojo/store/Memory" will be used as the cacheing repository. “ dojo / store / JsonRest”将获取数据,“ dojo / store / Memory”将用作缓存存储库。 The process of creating the cache is straight forward for a normal dojo web page. 对于普通的dojo网页,创建缓存的过程很简单。

require(["dojo/store/JsonRest", "dojo/store/Memory", "dojo/store/Cache", "dojo/store/Observable"], function(JsonRest, Memory, Cache, Observable){ masterStore = new JsonRest({ target: "/Inventory/" }); cacheStore = new Memory({}); inventoryStore = new Cache(masterStore, cacheStore);

However for a Dojox.app a config.json file is used to set up the various MVC components including data stores. 但是,对于Dojox.app,将使用config.json文件来设置各种MVC组件,包括数据存储。

The store and model portion of the json file could be similar to json文件的store和model部分可能类似于

   "stores": {
    "restStore":{
        "type": "dojo/store/JsonRest",
        "observable": true,
        "params": {
            "target": "/s/server/nowShowing.pl",
            "idProperty": "filmNo"
        }
    },
    "memoryStore": {
        "type": "dojo/store/Memory",
        "observable": true,
        "params": {
            "idProperty": "filmNo"
        }
    },
    "filmStore": {
        "type": "dojo/store/Cache",
         "params": {
            "masterStore": {"$ref":"#stores.restStore"},
            "cachingStore": {"$ref":"#stores.memoryStore"},
            "idProperty": "filmNo",
        }            
    }
},
"models": {
    "store": {
        "modelLoader": "dojox/app/utils/mvcModel",
        "type": "dojox/mvc/StoreRefController",
        "params":{
            "store": {"$ref":"#stores.filmStore"},
            "query": {}
        }
    }
},

I know that the cache store is a wrapper and not a true store. 我知道缓存存储区是包装器,而不是真正的存储区。 I also know that there would be a way to configure a dojo store cache via the config.json file but I haven't been able to find out how to do it. 我也知道,将有一种方法可以通过config.json文件配置dojo存储缓存,但我一直无法找到如何做的方法。 Mr Google didn't have the answer and the dojo tests came up blank as well. Google先生没有答案,dojo测试也变成空白。

The MVC model gives application wide access to the data via the loadedStores and loadedModels parameter of each view class. MVC模型通过每个视图类的loadedStores和loadedModels参数为应用程序提供了对数据的广泛访问。

您可以在此处(dojox.app)和此dojox.app参考指南中查看有关创建dojo商店的指南

There is no example, demonstration or dojo test, I have found, of reading data from a file into a Memory store via config.json. 我没有发现通过config.json将文件中的数据读取到内存存储中的示例,演示或dojo测试。 All of the tests on GitHub have the data as static json embedded in the app structure. GitHub上的所有测试都将数据作为静态json嵌入到应用程序结构中。

I need a way to get dynamic display data from the server to my app. 我需要一种从服务器到我的应用程序获取动态显示数据的方法。 After more research I hit upon a workaround. 经过更多研究后,我找到了解决方法。 It turns out that I didn't need use "dojo/store/Cache" to cache the data. 事实证明,我不需要使用“ dojo / store / Cache”来缓存数据。

Three easy steps. 三个简单的步骤。

  1. Modify the json file into a JS file by adding 通过添加将json文件修改为JS文件

var myJson = [{"filmNo":"2792",...

  1. Read the data into the app via a script link 通过脚本链接将数据读入应用程序

<script type="text/javascript" src="/s/server/myJsonFile.js"></script>

  1. In the config.json file make a reference to the myJson variable 在config.json文件中,引用myJson变量

"stores": { "filmStore": { "type": "dojo/store/Memory", "params": { "data" : "myJson", "idProperty": "filmNo" } }

Now my app really does zip from view to view 现在我的应用程序确实可以从一个视图压缩到另一个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM