[英]CollectionView help- Marionette JS
我是backbone.marioneete
的新手,并试图构建一个应用程序,该应用程序在从api 接收的表中列出一组用户。
到目前为止,这是我尝试过的。 我有两个模板 user_table.jst
<div class="bs-example">
<table class="table">
<thead class="thead-light">
<tr>
<th>Row</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
</tr>
</thead>
<tbody id="user_listing_table">
</tbody>
</table>
用户.jst
<td><%= id %></td>
<td><%= first_name %></td>
<td><%= last_name %></td>
<td><%= email %></td>
这些是我的视图文件
用户视图.js
import Marionette from 'backbone.marionette';
import template from '../templates/user.jst';
var UserView = Marionette.View.extend({
template: template,
tagName: 'tr'
});
export default UserView
用户视图
import Marionette from 'backbone.marionette';
import UserChildView from './UsersChildView';
import UserView from './UserView';
var UsersView = Marionette.CollectionView.extend({
childView: UserChildView,
childViewOptions: function(model, index) {
return {
collection: new Backbone.Collection(model)
};
}
});
用户子视图
import Marionette from 'backbone.marionette';
import template from '../templates/user_table.jst';
import UserView from './UserView'
var UsersChildView = Marionette.View.extend({
template: template,
regions: {
tableRegion: '#user_listing_table'
},
onRender() {
this.showChildView('tableRegion', new UserView());
}
});
export default UsersChildView
var userData = [
{
id: 1,
f_name: 'Test1F',
l_name: 'Test1L',
email: 'test1@test.com'
},
{
id: 2,
f_name: 'Test2F',
l_name: 'Test2L',
email: 'test2@test.com'
},
{
id: 3,
f_name: 'Test3F',
l_name: 'Test3L',
email: 'test3@test.com'
}
];
var UserItem = Backbone.Model.extend({});
var UserItemCollection = Backbone.Collection.extend({
model: UserItem
});
var itemCollection = new UserItemCollection(userData);
var layoutView = new UsersView({
collection: itemCollection
});
layoutView.render();
我无法将我的收藏传递给视图。 我在我的 user.jst 文件中收到错误说未定义的 id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.