在 ExtJS 中,调用 Model.save() 还是 Store.Sync() 更好? [英] in ExtJS, is it better to call Model.save() or Store.Sync()?

查看:17
本文介绍了在 ExtJS 中,调用 Model.save() 还是 Store.Sync() 更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每一个的后果是什么?

例如,我看到 Model.save() 会使用来自服务器的结果自动刷新模型.我不确定 sync() 是否可以.

I see that Model.save(), for example, automatically refreshes the Model with results from the server. I'm not sure if sync() does.

推荐答案

使用来自服务器的结果自动刷新模型

automatically refreshes the Model with results from the server

Store.sync() 也会刷新修改后的记录(前提是您已正确设置服务器响应).

Store.sync() refreshes modified records as well (provided you have setup the server response correctly).

因此,从技术上讲,这两种方法的作用相同.但是,在我看来,您只能在一种情况下使用 Model.save():当您没有 store 时.为什么?因为当您有商店但仍然使用 Model.save() 时,这意味着您已经为 storemodel 设置了连接(代理)配置>.这意味着您有可能更难维护的重复代码.

So, technically, both methods do the same. However, in my opinion, you can use Model.save() only in one case: when you don't have store. Why? Because when you have store and nevertheless you use Model.save() that's mean that you have setup connection (proxy) configuration for both store and model. And that's mean that you have duplicated code which is potentially harder to maintain.

所以,总而言之,只有在使用 独立模型 时才使用 Model.save(),而无需存储(当您有 没有连接到任何网格的表单.因此,您为此类表单创建独立模型),并在其他情况下使用 Store.sync().

So, to summarize, you use Model.save() only if you use standalone model, without store (it may be the case when you have form which is not connected to any grid. So you create standalone model for such form), and you use Store.sync() in other cases.

这篇关于在 ExtJS 中,调用 Model.save() 还是 Store.Sync() 更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆