多个表行作为Backbone.js的看法? [英] Multiple table rows as a backbone.js view?

查看:108
本文介绍了多个表行作为Backbone.js的看法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有数据的网格,并且网格中的每个项目具有关联的模型和视图。我需要渲染每个项目的两个表行,以达到预期的UI。 (不,这不是我的设计...)

So I have a grid of data, and each item in the grid has an associated model and view. I need to render each item as two table rows to achieve the desired UI. (No, it wasn't my design...)

第一次尝试:在视图的渲染()方法,只呈现两行并将它们添加到 this.el 。然后,我追加每个视图表,发现每对行已经包裹在一个< D​​IV> 。无效的HTML和布局是完全错误的。

First attempt: in the view's render() method, just render two rows and add them to this.el. Then I append each view to the table, and discover that every pair of rows has been wrapped in a <div>. Invalid HTML and the layout is all wrong.

好了,第二次尝试:在视图中再次呈现两行,但不是追加整个视图的表,我只是通过附加子行 tableItemView $(TR)<。 / code>。太棒了,它的作品!但坚持......现在该行事件已停止了射击。我发现这是因为骨干网使用 jQuery.delegate ,所以所有的事件被委托给原这是毫无该表的较长部分。

Ok, second attempt: render two rows in the view again, but instead of appending the entire view to the table, I just append the child rows by using tableItemView.$("tr"). Hooray, it works! But hold on ... the row events have now stopped firing. I discover this is because backbone uses jQuery.delegate, so all the events were delegated to the original el which is no longer part of the table.

我爱骨干干净架构,但很难找到一个很好的解决了这一点。任何想法?

I love backbone's clean architecture but struggle to find a nice solution to this. Any ideas?

推荐答案

设置

tagName: 'tbody' 

应该让你组相关的TR标记一起不破表,并仍然允许this.el工作。

should allow you to group the related tr tags together without breaking the table and still allow this.el to work.

这篇关于多个表行作为Backbone.js的看法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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