如何获得骨干事件的单元格视图单击
How to get the cell view on backbone event click?
当我触发点击一个单元格与骨干事件我没有得到单元格视图,我得到的行视图。
我正在发送模型和周属性给我的UserView。
所以我想要的是每个单元格都是一个唯一的骨干视图。有人能帮我吗?
骨干视图
app.types.UserView = Backbone.View.extend({
tagName: 'tr',
$sidebar: $('#userView'),
template: _.template($('#user-template').html()),
events:
{
//"click .test": "open",
"click td.test": "useri",
},
initialize: function(options)
{
this.options = options;
console.log("this.options", this.options.object.tjedan);
console.log("this.model: ", this.model);
this.$sidebar.append(this.render());
this.tableClick();
//this.open();
//this.getWeeksInMonth();
//console.log("this.tjedan: ", this.tjedan);
},
render: function()
{
this.$el.html(this.template(_.extend(this.model.attributes, {model_cid: this.model.cid, tjedan: this.options.object.tjedan})));
console.log("this.render: ", this);
return this.$el;
},
useri: function()
{
console.log("this.model", this);
}
});
HTML
<div class="container-fluid">
<div class="row">
<div id="collection" class="col-md-12 sidebar">
<table class="table">
<thead id="weekView">
<script type="text/template" id="week-template">
<th>Users</th>
<% for(var i=0;i<tjedan.length;i++)%> {
<th class="list-group week" scope="row"><%= tjedan[i].dan + " " + tjedan[i].datum + "." + tjedan[i].mjesecBrojevi + "." %></th>
}%>
</script>
</thead>
<tbody id="userView">
</tbody>
<script type="text/template" id="user-template">
<th class="list-group model" scope="row" data-cid="<%= model_cid %>"><%= username %></th>
<% for(var i=0;i<tjedan.length;i++)%> {
<td id="<%= id + tjedan[i].dan + tjedan[i].datum %>" class="list-group" scope="row" data-id="<%= model_cid + '_' + tjedan[i].dan + tjedan[i].datum + tjedan[i].mjesecBrojevi %>"></td>
}%>
</script>
</table>
</div>
</div>
</div>
您需要创建一个视图,它将作为单元格视图,并呈现每个单元格创建一个新视图。
细胞视图var CellView = Backbone.View.extend({
tagName: 'td',
className: 'list-group',
template: _.template('stuff inside your `td`'),
attributes: function() {
return {
id: this.model.get('your_choice'),
scope: 'row',
"data-id": this.whatever
};
},
events: {
"click": "onClick",
},
render: function() {
this.$el.empty().append(this.template(this.model.toJSON()));
return this;
},
onClick: function(e) {
// click on cell
}
});
行视图var RowView = Backbone.View.extend({
tagName: 'tr',
template: _.template('<th class="list-group model" scope="row" data-cid="<%= model_cid %>"><%= username %></th>'),
initialize: function(options) {
this.options = _.extend({ /* default options */ }, options);
this.childViews = [];
},
render: function() {
// when using extend, the first object is modified, `toJSON` returns
// a shallow copy of the attributes, avoiding modifying them.
var data = _.extend(this.model.toJSON(), {
model_cid: this.model.cid,
tjedan: this.options.object.tjedan
});
this.$el.empty().append(this.template(data));
this.collection.each(this.renderCell, this);
return this; // render always return this for chaining.
},
renderCell: function(model) {
var view = new CellView({
model: model
});
this.childViews.push(view);
this.$el.append(view.render().el);
},
remove: function() {
// explicitely remove the views to avoid memory leaks with listeners.
_.invoke(this.childViews, 'remove');
}
});
这只是一个如何渲染每个单元格视图的例子,它没有适当地考虑到你的模型和模板中的每个属性
相关文章:
- 使用jquery在单击时在单元格中输入值
- CSS-若窗口太小,滚动条会出现在“表格”单元格上
- 可以'我不明白为什么;t将行和单元格添加到表中
- 如何使用 javascript 修改网格视图单元格值
- 在客户端的编辑模式下,在同一单元格网格视图中选中复选框时禁用文本框
- C#网格视图从动态创建的DataTable中实现可点击单元格
- CakePHP3:如何使用视图单元格实现Facebook风格或堆栈式用户通知
- 如何在访问子网格视图时获取父网格视图的一个单元格的值
- 突出显示表视图单元格中的 uiwebview 文本
- 在Angular JS中使用移动视图时,表单元格中不会出现文本对齐
- 如何获取网格视图中单元格的值
- 如何在发生更改事件时从编辑器视图调用单元格视图的render方法
- jquery移动动态列表视图单元格高度
- 忽略包含下拉列表的网格视图单元格
- 通过第一列创建一个可展开的表格视图单元格
- 如何获得骨干事件的单元格视图单击
- javascript中网格视图单元格的超链接
- 如何从网格视图中获取特定的单元格值,并使用asp.net中的jquery将其显示在文本框中
- 在使用javascript和jquery计算网格视图单元格的总数时,得到错误
- Arshaw 全日历在月视图的每个单元格中添加自定义 html