javascript - 可以使用 Backbone 模型的 cid 作为 html id 属性吗?它保证是唯一的吗?

标签 javascript html backbone.js model

我有一个 Backbone View ,它显示来自几个不同集合的信息。可以使用那些模型的 cid 作为 html id 属性吗?换句话说,是否保证 cid 在所有集合中的所有模型中都是唯一的?

最佳答案

documentation says :

cid model.cid

A special property of models, the cid or client id is a unique identifier automatically assigned to all models when they're first created. Client ids are handy when the model has not yet been saved to the server, and does not yet have its eventual true id, but already needs to be visible in the UI.

没有提及集合或模型类型,因此它们应该足够安全。如果说模型被破坏,则不能保证给定的 cid 不会被重用,但这对您来说可能无关紧要,cid 的唯一明智的实现是当需要新的 cid 时,某种单一的全局计数器会增加。

OTOH,如果我有可用的真实模型 id,我会改用它们。

关于javascript - 可以使用 Backbone 模型的 cid 作为 html id 属性吗?它保证是唯一的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18994306/

相关文章:

javascript - “组件”不能用作 JSX 组件。下一页

javascript - 构建 backbone.js 应用程序

javascript - 如何按图库的 ID 过滤 div 元素

javascript - 在一个div中水平居中几个不同宽度的div

javascript - 尽管尚未加载 dom,但如何在主干中声明 jquery 元素

java - GWT:在 Java 代码中捕获 native JSNI 异常

php - 博客的结构应该是怎样的?

javascript - 无法测试去抖动的 Backbone View 事件

html - 应用了 z-index 的 div 可以 float 吗?

javascript - Backbone : Batch save models in single request?