Dojo 中是否有相当于 Dictionary 或类似集合的东西?

Is there an equivalent to Dictionary or similar collection in Dojo?

我正在寻找一种方法来将对象存储在集合中并通过 UUID 识别它们,然后查询集合以通过 UUID 获取对象。我能想到的最接近的示例是 .NET 中的 Dictionary 集合。 Dojo 中是否有为此推荐的功能?

JavaScript 中没有此类对象的集合。但是您可以创建自己的对象,如下所示

var coll = { uid : "value" };
coll['uid2'] = "value2;

可以使用

访问
var a = coll['uid'];

这就是JavaScript的魅力。

dojo 中没有等效项,即使 dojo/store/Memory 模块不是用于此目的,您也可以以某种方式将其用作集合,请查看:

require(["dojo/store/Memory"], function(Memory){
    var someData = [
        {id:1, name:"One"},
        {id:2, name:"Two"}
    ];

    store = new Memory({
        idProperty: "id", //define the id property
        data: someData
    });

    // Returns the object with an id of 1
    store.get(1);

    // Returns query results from the array that match the given query
    store.query({name:"One"});

    // Pass a function to do more complex querying
    store.query(function(object){
        return object.id > 1;
    });

    // Returns query results and sort by id
    store.query({name:"One"}, {sort: [{attribute: "id"}]});

    // store the object with the given identity
    store.put({id:3, name:"Three"}); 

    // delete the object
    store.remove(3); 
});

dojo 有其他类型的 store,可能比 dojo/store/Memory 更适合您的情况。以下是一些文档链接:

dojo/store/Memory
dojo/store/JsonRest
dojo/store/DataStore
dojo/store/Cache

还有其他的,但这是必须的