Php 从dojo数据网格中删除项
在我的Zend Framework项目中,我正在努力使用一个简单的dojo数据网格 我可以显示mysql表中的数据列表,但是我希望用户能够删除选定的行(并从数据库中删除它们)。我使用的例子来自。我的datagrid视图中的代码如下所示Php 从dojo数据网格中删除项,php,zend-framework,dojo,Php,Zend Framework,Dojo,在我的Zend Framework项目中,我正在努力使用一个简单的dojo数据网格 我可以显示mysql表中的数据列表,但是我希望用户能够删除选定的行(并从数据库中删除它们)。我使用的例子来自。我的datagrid视图中的代码如下所示 <div dojoType="dojo.data.ItemFileReadStore" jsId="skillstore" url="<?php echo $this->baseUrl()?>
<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>
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
}
我遇到的主要问题是,当我选择一行并单击按钮时,Firebug抱怨skillstore.deleteItem不是一个函数。我还没有尝试从数据库中删除该条目
任何指针都将不胜感激。我认为您所要做的就是使用
jsId
属性值作为ID,而不是ID
一个:
var items = skills.selection.getSelected();
编辑:
如果这不起作用,您是否在结束正文
标记后添加了以下内容
<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>
require(“dojox.grid.DataGrid”);
require(“dojo.data.ItemFileWriteStore”);
require(“dijit.form.Button”);
EDIT2:
实际上,您使用的是只读存储,这就是问题所在。我可以这样做
声明dojo.require(“dojo.data.ItemFileWriteStore”);这是必须的。这就是Firebug抱怨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
}
什么是
skillstore
?我看到它是表的store
属性。我不太了解Dojo-这是否意味着它是自动初始化的?遗憾的是,我仍然会收到关于selectedItem的相同错误。deleteItem不是函数??感谢这一点,但是我现在在Dojo.js文件中有一条不同的错误消息Dojo.data.ItemFileReadStore:invalid item参数。我已经检查了代码,以确保网格的所有引用都使用ItemFileWriteStore。有什么想法吗?这有帮助吗(尤其是第一个答案)@Franz你提供的链接已断开。请提供其他链接。可能是以下链接: