TypeError:datastore.getRootCollection不是函数

时间:2016-09-09 18:06:19

标签: dojo

我假设使用dmodel创建的dstore仍然是dstore并继承了所有dstore功能。所以有一个名为getRootCollection的方法,但是当我尝试在商店运行这个方法时,它失败并出现错误(没有这样的功能)

这是我的代码

<script>

    require(
        [
        'dojo/_base/declare',
        'dstore/Memory',
        'dmodel/extensions/jsonSchema',
        'dmodel/validators/StringValidator',
        'dmodel/store/Validating',
        "dmodel/Model"
        ], 
    function (declare, Memory, jsonSchema, StringValidator, Validating, Model) {

        var vMem = (declare([Memory, Validating]))({
            Model: jsonSchema(
            {
                "$schema": "http://json-schema.org/draft-04/schema",
                "description": "my schema",
                "type": "object",
                "properties": {
                    "page": {
                        "type": "object",
                        "properties": {
                            "detailsCanvas": {
                                "description": "test value",
                                "type": "object",
                                "$ref": "#/definitions/details"
                            }
                        }
                    },
                    "elements": {
                        "type": "array",
                        "items": {
                            "title": "Element",
                            "type": "object",
                            "properties": {
                                "id": {
                                    "type": "string"
                                },
                                "positionX": {
                                    "description": "The X coordinate",
                                    "type": "number"
                                },
                                "elementSpecificProperties": {
                                    "type": "object",
                                    "oneOf": [
                                      { "$ref": "#/definitions/label" }
                                    ]
                                }
                            }
                        }

                    }
                },

                "definitions": {

                    "details": {
                        "type": "object",
                        "properties": {
                            "height": {
                                "type": "string"
                            }
                        }
                    },

                    "label": {
                        "type": "object",
                        "properties": {
                            "value": {
                                "type": "string"

                            }
                        }
                    }
                }
            }

            )
        });

        vMem.setData(
        {
            "page": {
                "detailsCanvas": {
                    "height": "100px"
                }
            },
            "elements": [
                {
                    "id": "1",
                    "positionX": 20,
                    "elementSpecificProperties": {
                        "value": "value_1"
                    }
                },
                {
                    "id": "2",
                    "positionX": 5,
                    "elementSpecificProperties": {
                        "value": "value_2"
                    }
                }
            ]
        });

        var blah = vMem.getRootCollection(); //type error - getRootCollection is not a function


    });
</script>

1 个答案:

答案 0 :(得分:0)

getRootCollection()是dstore的Tree模型的一部分。你只混合dstore/Memory。这就是你得到那个错误的原因。查看documentation of dstore以获取更多信息。