itemfilereadstore从json文件读取

时间:2014-03-20 12:21:15

标签: 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>

非常感谢任何帮助

1 个答案:

答案 0 :(得分:0)

你看过JsonRest商店而不是ItemFileReadStore吗? http://dojotoolkit.org/reference-guide/1.9/dojo/store/JsonRest.html