【问题标题】:removing items from a dojo datagrid从 dojo 数据网格中删除项目
【发布时间】:2009-11-28 12:05:42
【问题描述】:

我在 Zend Framework 项目中遇到了一个简单的 dojo 数据网格。

我有一个可以显示的 mysql 表中的数据列表,但是我希望用户能够删除选定的行(并将它们从数据库中删除)。我正在使用来自Dojo DataGrid adding and deleting data 的示例。我的数据网格视图中的代码如下所示。

<div dojoType="dojo.data.ItemFileReadStore" jsId="skillstore" url="<?php echo $this->baseUrl()?>/skills/hist/<?php echo $this->histid;?>"></div>

<table id="skillgrid" jsId="skills" dojoType="dojox.grid.DataGrid" store="skillstore"   style="height:300px;width:500px;">
 <thead>
    <tr>
        <th field="skillid" hidden="true"></th>
        <th width="auto" field="skill">Skills</th>
    </tr>
        
</thead>
</table>
<div>
<button dojoType="dijit.form.Button" onclick="removeRows()" >Remove Selected Row</button>
<button dojoType="dijit.form.Button" onclick="addRow()">Add another skill</button>
</div>

我已经在视图脚本 captureStart 和 captureEnd 标记之间放置了用于删除行的代码。 removeRows() 的代码如下所示。

function removeRows(e){     
    var items = skillsgrid.selection.getSelected();
    
    if(items.length){
    
        dojo.forEach(items, function(selectedItem){
        
            if(selectedItem !== null){
                            
                skillstore.deleteItem(selectedItem);
            }//endif
        });//end foreach
    
    }//end if
}

我遇到的主要问题是,当我选择一行并单击按钮时,萤火虫抱怨说 Skillstore.deleteItem 不是一个函数。我还没有尝试从数据库中删除该条目。

任何指针将不胜感激。

【问题讨论】:

  • skillstore 到底是什么?我看到它是表的store 属性。我不太了解 Dojo - 那是否意味着它是自动初始化的?

标签: php zend-framework dojo


【解决方案1】:

我会做这些。

声明 dojo.require("dojo.data.ItemFileWriteStore");是必须的。这就是为什么萤火虫抱怨 Skillstore.deleteItem 不是函数的原因,因为在 ItemFileReadStore 中没有“deleteItem”,但在“ItemFileWriteStore”中找到。

function removeRows(e){         
        var items = skillsgrid.selection.getSelected();
        if(items.length){
                dojo.forEach(items, function(selectedItem){
                      skillsgrid.store.deleteItem(selectedItem); 
                      skillsgrid.sort(); // I did access the store of the grid directly.
                });//end foreach

        }//end if
}

【讨论】:

    【解决方案2】:

    我认为您所要做的就是使用jsId 属性值作为ID 而不是id 之一:

    var items = skills.selection.getSelected();
    

    编辑

    如果这不起作用,您是否在结束 body 标记之后添加了以下内容?

    <script type="text/javascript" src="dojo.js" djConfig="parseOnLoad: true">
    </script>
    <script type="text/javascript">
        dojo.require("dojox.grid.DataGrid");
        dojo.require("dojo.data.ItemFileWriteStore");
        dojo.require("dijit.form.Button");
    </script>
    

    EDIT2

    实际上,您使用的是只读存储,这就是问题所在。

    【讨论】:

    • 遗憾的是,我仍然收到关于 selectedItem.deleteItem is not a function 的相同错误??
    • 感谢您,但是我现在在 dojo.js 文件中收到了关于 dojo.data.ItemFileReadStore: invalid item 参数的不同错误消息。我检查了我的代码以确保网格的所有引用都在使用 ItemFileWriteStore。有什么想法吗?
    • 这有帮助吗(尤其是第一个答案)? dojotoolkit.org/forum/dojox-dojox/dojox-grid-support/…
    • @Franz 您提供的链接已关闭。请提供其他链接。
    猜你喜欢
    • 2023-03-20
    • 2013-08-28
    • 1970-01-01
    • 2012-02-09
    • 2016-01-14
    • 1970-01-01
    • 1970-01-01
    • 2014-07-06
    • 2021-01-29
    相关资源
    最近更新 更多