我有一个 Backbone View ,它显示来自几个不同集合的信息。可以使用那些模型的 cid 作为 html id 属性吗?换句话说,是否保证 cid 在所有集合中的所有模型中都是唯一的?
最佳答案
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/