Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Backbone.js 如何将木偶3 CollectionView呈现到表列中?_Backbone.js_Marionette - Fatal编程技术网

Backbone.js 如何将木偶3 CollectionView呈现到表列中?

Backbone.js 如何将木偶3 CollectionView呈现到表列中?,backbone.js,marionette,Backbone.js,Marionette,我目前正在使用symfony 1.4和一些过时的技术开发一个遗留程序。最近,我们决定将主干网/木偶网添加到项目中,以使事情变得更简单 我面临的问题是将集合视图渲染为表列。该表已经存在,并且具有超过2k LOC的功能,这使得我无法重写它 <table> <thead> <tr> <th>Item</th> <th>Quantity</th> <th>Price</th>

我目前正在使用symfony 1.4和一些过时的技术开发一个遗留程序。最近,我们决定将主干网/木偶网添加到项目中,以使事情变得更简单

我面临的问题是将集合视图渲染为表列。该表已经存在,并且具有超过2k LOC的功能,这使得我无法重写它

<table>
<thead>
<tr>
    <th>Item</th>
    <th>Quantity</th>
    <th>Price</th>
    <th>...</th>
    <th></th> <!-- This is the column -->
    <th>Total price</th>
</tr>
</thead>
<tbody>
    ...
</tbody>
</table>

项目
量
价格
...
总价
...
除注释指定的列外,所有其他列都已呈现到页面中。我已经按照文档进行了操作,但无法实施有效的解决方案。

var collection=新主干。集合([
{id:1,文本:'one'},
{id:2,文本:'two'},
{id:3,文本:'3'},
{id:4,文本:'four'},
{id:5,文本:'5'},
{id:6,文本:'six'},
{id:7,文本:'seven'}
])
var MyChildView=Mn.View.extend({
初始化(){
这个。render();
},
模板:\.template(“:”)
});
var CollectionView=Mn.CollectionView.extend({
el:“.t车身挂钩”,
childView:MyChildView,
buildChildView(模型,子视图){
变量视图=新的子视图({
el:'.td-'+model.id,
型号:型号
}); 
返回视图;
},
附件HTML:uu.noop,
附件缓冲区:u0.noop
});
var myRegion=新的木偶区域({el:'#some Region'});
show(newcollectionview({collection:collection}));
使用collectionview通过列选择器管理预渲染的子级。您需要禁用collectionview将子对象附加到它自己的容器,并且需要强制子对象在实例化后呈现自己

var collection = new Backbone.Collection([
  { id: 1, text: 'one' },
  { id: 2, text: 'two' },
  { id: 3, text: 'three' },
  { id: 4, text: 'four' },
  { id: 5, text: 'five' },
  { id: 6, text: 'six' },
  { id: 7, text: 'seven' }
])

var MyChildView = Mn.View.extend({
  initialize() {
    this.render();
  },
  template: _.template(': <%- text %>')
});
var CollectionView = Mn.CollectionView.extend({
  el: '.tbody-hook',
  childView: MyChildView,
  buildChildView(model, ChildView) {
    var view = new ChildView({
      el: '.td-' + model.id,
      model: model
    }); 
    return view;
  },
  attachHtml: _.noop,
  attachBuffer: _.noop
});

var myRegion = new Marionette.Region({ el: '#some-region' });

myRegion.show(new CollectionView({ collection: collection }));