DOM 元素作为 BackboneJS 中的模型属性
我正在制作类似的东西:
http://orange .blender.org/wp-content/themes/orange/images/blog/noodles.jpg
我的 NodeGraph 模型由节点和连接组成。我的连接模型包含FromNode、FromProperty 和ToNode、ToProperty。绘制连接时,我想找到“点”关联的 DOM 元素。问题是这是一个依赖于视图的属性(甚至可能在浏览器之间有所不同)。我应该将此信息从视图发送回模型吗?或者我应该做点别的事情?
I am making something similar to this:
http://orange.blender.org/wp-content/themes/orange/images/blog/noodles.jpg
My NodeGraph model consists of Nodes and Connections. My Connection model contains FromNode, FromProperty and ToNode, ToProperty. When drawing the connection, I want to find the associated DOM element for the "dot". The problem is that this is a View-dependent property (and may even differ between browsers). Should I send this info FROM the view back to the model? Or should I be doing something else?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我确信我不完全理解你的问题,但这里有一个简短的答案。
将节点和连接模型创建为纯模型,无需任何视图引用。这些模型将同时具有 id 和 cid 属性。 cid由backbone.js分配。该 ID 将由您的服务器分配。鉴于这些属性的存在,您现在拥有这些模型的身份。
现在,在您的视图中,您可以使用 id 或 cid 之一作为 DOM id — 您可以使用它们作为 id,或者您可能需要将它们用作 DOM id 的组件(例如“connect-24”) 。
I am sure I don't completely understand your question, but here's a short answer.
Create your Node and Connection models as pure models without any View references. These models will have both an id and a cid property. The cid is assigned by backbone.js. The id would be assigned by your server. Given the presence of these properties, you now have identity for these models.
Now in your view(s), you can use either one of id or cid as DOM ids—you may use these as the id or you may need to use them as a component of a DOM id (e.g. 'connect-24').