extjs 4自动生成记录id

发布于 2024-12-29 03:12:50 字数 336 浏览 1 评论 0原文

我有一个可以添加和删除功能的地图,并使用 extjs 4 网格面板作为视图 (MVC) 来列出功能。这个想法是,用户可以单击网格中的一个项目并在地图中突出显示它,单击按钮将其删除等。这些功能没有自然键,所以我需要弥补一个,只需一个数字就可以了。目前,地图启动时已经有一些功能,因此我可以循环遍历并给每个功能一个 id,并为每个功能向商店添加一条记录以将两者联系起来,但理想情况下我希望商店能够处理添加每条记录时。我还遇到一个问题,当创建新功能时,我需要获得一个新的 id 来使用,但我不想遍历所有功能来找到最高的 id。 我正在使用 myStore.add({id:1,name:'blah'...}) 添加记录 - 我应该使用它还是插入? 任何帮助表示赞赏

I have a map to which features can be added and removed and am using an extjs 4 grid panel as a view (MVC) to list the features. The idea is that the user can click an item in the grid and highlight it in the map, click a button to remove it etc. The features do not have a natural key so I need to make one up, just a number is fine. At the moment the map starts up with some features already on it so I am able to loop through and give each an id and add a record to the store for each to tie the 2 up, but ideally I want the store to take care of that when each record is added. I also have the problem that when a new feature is created I need to get a fresh new id to use but I'd rather not have to loop through all my features to find the highest id.
I am using myStore.add({id:1,name:'blah'...}) to add the records - should I be using this or insert?
Any help appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑红尘 2025-01-05 03:12:50

是的,您可以使用 store last 来找出您的最后一条记录,但我的建议是在服务器端处理 ID 生成。通常,数据库排序器用于创建 ID。

Yes you can use the store last to figure out your last record, but my recommendation is to handle ID generation to the server side. Typically database sequencer is used to create IDs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文