ExtJS 4 - 更新/刷新单个记录
我有一个问题困扰着我。
我有一个网格,当我双击某个项目时,我想打开一个窗口来编辑该项目。相当标准的东西。问题是,我想确保记录是最新的,因为使用该程序的其他人可能已经更改了它甚至删除了它。
我可以重新加载商店,但我只想检查一个特定记录...所以我想我会去获取数据,构建另一条记录并替换商店中的现有记录,但我真的想知道最好的方法 请
记住,RESTful 代理对我来说不是一个选择,即使我不知道更新操作在这种情况下是否有效(服务器 -> 客户端)。
编辑: 这可能会帮助某人: 我所做的就是将数据和原始对象从新记录复制到旧记录,然后“提交”更改。为我工作。
谢谢。
I have a problem that's bugging me.
I have a grid and when i dblclick on a item I want to open a window to edit that item. Pretty standard stuff. The problem is, i want to be sure the record is up to date, because other people using the program may have changed it or even deleted it.
I could reload the store, but i only want one specific record to be checked... So i figured i would just go get the data, build another record and replace the existing one in the store but i really want to know the best way to do this
Bear in mind RESTful proxy is not an option for me, even though i don't know if the update operation works in this case ( server -> client).
EDIT:
this may help somebody:
all i did was copy the data and raw objects from the new record to the old one and then "commit" the changes. worked for me.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
ExtJS 4.1
我遇到了类似的问题,作为实验尝试了
sStore.load({
id:mskey,
添加记录:true
});
其中 mskey 是当前加载记录的 uuid。
我没有首先删除现有记录(作为实验),它更新与服务器中的新数据具有相同 ID 的现有记录(通过模型 - -> REST 代理)。完美的!
我知道您说过您没有使用 REST 代理,但这可能会帮助其他人发现这篇文章搜索您的主题名称等搜索词(这就是我到达这里的方式!)
所以,它看起来像“addRecords”意味着添加 或更新。
供参考,
穆雷
ExtJS 4.1
I had a similar problem and as an experiment tried
sStore.load({
id: mskey,
addRecords: true
});
where mskey is a uuid of a currently loaded record.
I did not remove the existing record first (as an experiment) and it updated the existing record that had the same id with the new data from the server (via the model --> REST proxy). Perfect!
I know you said you are not using a REST proxy, but this might help others who found this post searching for search terms like your topic name (which is how I got here!)
So, it looks like 'addRecords' means add or update.
FYI,
Murray
执行此类操作的最佳方法是在打开窗口的事件中重新加载记录。因此,例如,当您将网格存储中的记录加载到窗口内的表单中时,您可以使用模型从 id 加载。
保存后,您可能还应该在网格视图上调用刷新,这将重新绘制保存事件中的更改。您还可以使用refreshNode(查看网格视图文档) 如果您担心性能,请查看商店中的确切记录。
当然,您不必使用restful代理,您可以使用任何代理,只要它能够加载单个记录即可。
The best way to do something like this would be to reload the record in the event which opens the window. So where you would for example load the record from the grid store into a form within the window, you can use your model to load from the id.
Once saved, you should probably also call refresh on the grid view, which will redraw the changes from the save event. You can also use refreshNode (see grid view documentation) on the exact record in the store if you're concerned about performance.
Of course you do not have to use the restful proxy with this, you can use any proxy as long as it will load the single record.
对于 ExtJS 4.1,这里有一个覆盖:
在 CoffeeScript 中:
在 JS 中(未测试):
With ExtJS 4.1, here is an override :
In CoffeeScript :
In JS (did not test) :
我在 Ext.data.Model 上创建了一个重写,以添加可用于更新现有记录(模型实例)的数据的附加方法。
您可以这样使用它。它实际上非常简单:
在内部它使用关联模型上的 load 方法来创建新记录。该新记录基于与调用 reloadData 方法的原始记录相同的 id。在回调中,新记录的数据将应用于原始记录的数据。没有触发任何事件,这可能是您想要的。
这是分机 4.2.1。该解决方案可能会破坏数十种场景,但我们总是可以进行改进,不是吗?
更新:该解决方案基本上与@Drasill 的解决方案实现相同。哦,好吧...不过这个已经经过测试了。
I created an override on the Ext.data.Model to add an additional method that can be used to update the data of an existing record (model instance).
This is how you can use it. It's actually pretty simple:
Internally it uses the load method on the associated model to create a new record. That new record is based on the same id as the original record that the reloadData method was called on. In the callback the data of the new record is applied to the data of the original record. No events triggered, which is probably hat you want.
This is Ext 4.2.1. There's probably dozens of scenario's that this solution breaks but we can always refine can't we.
Update: This solution basically implements the same as the one by @Drasill. Oh well... This one was tested though.