Dgrid 0.4 和 dstore:在 UI 中更新行而不需要放置请求

Posted

技术标签:

【中文标题】Dgrid 0.4 和 dstore:在 UI 中更新行而不需要放置请求【英文标题】:Dgrid 0.4 and dstore: update row in UI without put request 【发布时间】:2015-03-27 09:22:36 【问题描述】:

在 Dgrid 0.3.16 中,我使用的是 Observable 存储,当我在存储中的数据发生更改时,我调用了存储通知函数。 (不是 'put',因为我只需要 UI 更新,这是特定情况)

store.notify(object, existingId);

我现在已将 Dgrid 升级到 0.4 版,并且我使用 'dstore' 作为商店。商店是这样创建的:

        var store = new declare([ Rest, SimpleQuery, Trackable, Cache, TreeStore ])(lang.mixin(
            target:"/ac/api?fetchview",
            idProperty:"$uniqueid", 
            useRangeHeaders: true
        , config));

        store.getRootCollection = function (parent, options) 
            return this.root.filter(parent: parent.$position,options);
        ;

        store.getChildren = function (parent, options) 
            return this.root.filter(parent: parent.$position,options);
        ;

        store.mayHaveChildren = function (item) 
            return item.$iscategory;
        ;

        this.collection = store;

如果更改了一行而不调用“put”,我如何通知商店?我需要 dGrid 重新渲染该行。

【问题讨论】:

【参考方案1】:

dstore 遵循的模型更类似于典型的事件驱动方法,使用 onemit 方法。 dstore 支持 addupdatedelete 事件 - 前两个期望具有引用该项目的 target 属性的对象; delete 事件需要一个具有 id 属性的对象,该属性引用项目的身份。

所以要通知更新的项目,请致电store.emit('update', target: updatedItem )

emit 方法记录在Store methods 下,事件类型在Collection documentation 中进一步列举。

【讨论】:

谢谢,这行得通,但是当我的项目是树父级中的孩子时,项目会在错误的位置更新。它将在当前树父级的第一个子级之前移动。如何保持更新项目的当前位置? 应该可以保持顺序 - 例如编辑和保存儿童作品在Tree test page。如果您可以提供有关您的特定案例的更多详细信息(例如,您正在使用哪些商店模块),那么为此提出另一个问题可能是有意义的。 我删除了我之前的评论。问题是我在我的商店中使用了这些 mixin:Rest、Trackable、TreeStore、SimpleQuery。一旦我删除“SimpleQuery”,所有项目在 store.emit('update'... .

以上是关于Dgrid 0.4 和 dstore:在 UI 中更新行而不需要放置请求的主要内容,如果未能解决你的问题,请参考以下文章

将列添加到 dstore 支持的 dgrid

Dojo dGrid/dStore 实时更新

Dojo dgrid dstore 集合 - “或”过滤器不起作用

使用 dstore Rest 在查询参数中禁用过滤器

如何使用 contains 方法过滤 dstore?

dgrid 0.4.0 树在用户交互之前看起来很平坦