从Grails“渲染为json”中填充dojo ItemFileReadStore

Populate dojo ItemFileReadStore from Grails "render as JSON"

本文关键字:填充 dojo ItemFileReadStore json 渲染为 Grails      更新时间:2023-09-26

我在控制器中创建了一个方法,如果我直接浏览到该URL,它将给我一个JSON"文件"。它只在内存中,而不是在磁盘上,因为它是在您点击URL时生成的。我试图使用它作为dojo树的数据存储,但是,当我使用它时,树永远不会填充,它只是坐在那里的"等待"游标。是否有不同的方法来填充树的数据?

下面是代码。"getFilterTree"返回grails中呈现的JSON对象

       var store = new dojo.data.ItemFileReadStore({
           url: "/SkillsDB/search/getFilterTree"
       });
       var treeModel = new dijit.tree.ForestStoreModel({
           store: store,
           query: {
               "type":"cat"
           },
           rootId: "root",
           rootLabel: "Filter Categories",
           childrenAttrs: ["children"]
       });
       new dijit.Tree({
           model: treeModel
       },
       "treeOne");

应该没问题。

对于ItemFileReadStore,您的json应该符合本页所示的结构:http://dojotoolkit.org/reference-guide/dojo/data/ItemFileReadStore.html