如何在Dojo中更改ObjectStoreModel的默认值

How to change the defaults value for ObjectStoreModel in Dojo?

本文关键字:ObjectStoreModel 默认值 Dojo      更新时间:2023-09-26

我使用Dojo ObjectStoreModel作为dijit/Tree小部件。为了匹配我的数据结构,我需要将ObjectStoreModel配置为使用名为parent_id的属性,而不是默认的parent

知道如何设置这个配置吗?

   var data = [
      {
        id: 'world',
        name: 'The earth',
        type: 'planet',
        population: '6 billion'
      },
      {
        id: 'EG',
        name: 'Egypt',
        type: 'country',
        parent_id: 'AF' // does not work if property is called parent_id, only parent by default
      },
      {
        id: 'Nairobi',
        name: 'Nairobi',
        type: 'city',
        parent_id: 'KE'
      },
      {
        id: 'Mombasa',
        name: 'Mombasa',
        type: 'city',
        parent_id: 'KE'
      },
      {
        id: 'SD',
        name: 'Sudan',
        type: 'country',
        parent_id: 'AF'
      },
    ];

            var myStore = new Memory({
                data: data,
                getChildren: function (object) {
                    return this.query({ parent: object.id });
                }
            });
            // Create the model
            var myModel = new ObjectStoreModel({
                store: myStore,
                query: { id: '0' }
            });

            // Create the Tree.
            var tree = new Tree({
                model: myModel
            });
            tree.placeAt(this.domNode);
            tree.startup();

我找到了问题的解决方案

http://dojotoolkit.org/reference-guide/1.10/dijit/tree/ObjectStoreModel.html

驻车:The dojo.store must implement it’s own getChildren() method.

因此,使用此编辑脚本可以很好地工作。

var myStore = new Memory({
                data: data,
                getChildren: function (object) {
                    return this.query({ parent_id: object.id });
                }
            });
相关文章:
  • 没有找到相关文章