关于 dojo.data.ItemFileWriteStore & dojox.grid.DataGrid 一个注意事项

修改内存中的 store 后, DataGrid 的内容本应该自动更新, 但是今天在 coding 的时候却出现了异常, store 添加一个 item 成功, 但是用这个 store 的 DataGrid 内容别没有显示更新后的结果, 检查 一下, 发现了问题所在, 特此记录下来.


var store = new dojo.data.ItemFileWriteStore({
    url: "fruit.json"
});
var grid = new dojox.grid.DataGrid({
	store: store,
	query: {name: '*'},
	structure :[{
		name : "Name",
		field : "name",
		width : "50%"
	}, {
		name : "Color",
		field : "color",
		width : "50%"
	}]
}, "mygrid");

fruit.json

{
	"identifier": "name",
	"items": [
		{
			"name": "banana",
			"color": "yellow"
		},
		{
			"name": "apple",
			"color": "red"
		}
	]
}

由于 dojo.data.ItemFileWriteStore 实现了 Notification 接口, store 也就有了 onNew, onSet, onDelete.

DataGrid 会 connect 自已内部的 _onNew, _onSet, _onDelete 到 Notification API 中的 onNew, onSet, onDelete上.

今天出问题的原因是 :

store.onNew = function() {}
store.onDelete = function() {}

的定义放在了

var grid = new dojox.grid.DataGrid({})

后. 覆盖掉了 DataGrid 的 connect  _onNew 等方法.


另 dojox.grid.DataGrid 刷新 grid 的内部方法为 _refresh();

grid._refresh();


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值