javascript - itemfilereadstore 从 json 文件读取

标签 javascript json dojo

我从 Dojo 开始,尝试从 json 文件中显示缩略图库,但到目前为止还没有成功。我搜索并查看了其他示例,但没有一个对我有帮助。请帮我看看我做错了什么。

在脚本中指定数据时它可以工作(如注释掉的代码所示),但我无法让它从外部文件读取数据。

到目前为止我的代码:

 <script>

    require(["dojo/ready",
         "dijit/registry",
         "dojo/dom",
         "dojo/on",
         "dojo/parser",
         "dojo/data/ItemFileReadStore",
         "dojox/image/Gallery"
    ], function (ready, registry, dom, on, parser, ifrs, Gallery) {

        ready(function () {
            // Define the attribute names used to access the items in the data store
            parser.parse();
            var itemNameMap = {
                imageThumbAttr: "thumb",
                imageLargeAttr: "large"
            };

            // Define the request, with no query, and a count of 20, so 20 items will be
            // requested with each request
            var request = {
                query: {},
                count: 20
            };
            // var store = new ifrs(imgs);

         /*   imageItemStore.data = {
                identifier: 'title',
                label: 'Images',
                items: [
                    {
                        thumb: "http://www.flickr.com/photos/44153025@N00/748348847",
                        large: "http://www.flickr.com/photos/44153025@N00/748348847",
                        title: "Photo"
                    }
                ]
            };*/
                imageItemStore = new dojo.data.ItemFileReadStore({ url: "/images.json" });
                registry.byId('gallery1').setDataStore(imageItemStore, request, itemNameMap);

        });
    });
        </script>

我的 json 文件:

{ items: [
{
  "thumb":"images/extraWide.jpg",
  "large":"images/extraWide.jpg",
  "title":"I'm wide, me",
  "link":"http://www.flickr.com/photos/44153025@N00/748348847"
},
{
 "thumb":"images/imageHoriz.jpg",
  "large":"images/imageHoriz.jpg",
  "title":"I'm a horizontal picture",
  "link":"http://www.flickr.com/photos/44153025@N00/735656038"
},
{
  "thumb":"images/imageHoriz2.jpg",
  "large":"images/imageHoriz2.jpg",
  "title":"I'm another horizontal picture",
  "link":"http://www.flickr.com/photos/44153025@N00/714540483"
},
{
 "thumb":"images/imageVert.jpg",
  "large":"images/imageVert.jpg",
  "title":"I'm a vertical picture",
  "link":"http://www.flickr.com/photos/44153025@N00/715392758"
},
{
 "large":"images/square.jpg",
 "thumb":"images/square.jpg",
 "link" :"images/square.jpg",
 "title":"1:1 aspect ratio"
}
]}

我的标记:

<div class="claro" style="height:400px">
        <div data-dojo-type="dojox.image.Gallery" id="gallery1" style="height:400px"></div>
    <div data-dojo-id="imageItemStore" data-dojo-type="dojo.data.ItemFileReadStore"></div>
    </div>

任何帮助将不胜感激

最佳答案

您是否查看过 JsonRest 存储而不是 ItemFileReadStore? http://dojotoolkit.org/reference-guide/1.9/dojo/store/JsonRest.html

关于javascript - itemfilereadstore 从 json 文件读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22532871/

相关文章:

javascript - 取消单独和所有 axios 请求

javascript - 模糊事件上的 Typeahead.js

Android json 解析不工作

javascript - 如何阻止 dojo 滚动以形成焦点小部件?

javascript - 如何从父对象获取对象的属性值

python - 如何在 Google App Engine 中解析 JSON?

java - 谷歌 gson fromjson() TypeToken

javascript - 处理dojo EdgeToEdgeStoreList事件

javascript - 如何禁用由 html 创建的特定 dijit contentPane 选项卡?

javascript - 为 javascript 创建 Repl.it 函数 boolean 值时出现问题