[英]backbone and marionette, ItemView not rendering, how to?
for some reason the ItemView doesn't render. 由于某种原因,ItemView无法渲染。 Here is my setup:
这是我的设置:
controller 控制者
test: function () {
require(['application', 'collections/collection-test', 'views/collection/view-test'], function (App, CollectionTest, ViewTest) {
var collectionTest = new CollectionTest();
App.regionTest.show(new ViewTest({
collection: collectionTest
}));
});
},
collection view 集合视图
define(['backbone','views/item/itemview-test'],
function (Backbone, ItemviewTest) {
'use strict';
return Backbone.Marionette.CollectionView.extend({
tagName: 'ul',
initialize: function () {},
itemView: ItemviewTest,
ui: {},
events: {},
/* on render callback */
onRender: function () {
console.log(this.$el);
}
});
});
item view 项目视图
define(['backbone','hbs!tmpl/item/itemview-test_tmpl'],
function (Backbone, ItemviewTestTmpl) {
'use strict';
return Backbone.Marionette.ItemView.extend({
tagName: 'li',
initialize: function (options) {},
template: ItemviewTestTmpl,
ui: {},
events: {},
onRender: function () {
console.log(this.$el);
},
});
});
i can see the <ul></ul>
being added to the region, but not the li
我可以看到
<ul></ul>
已添加到该区域,但li
却没有
i can render the li
if i replace 'views/collection/view-test'
with 'views/item/itemview-test'
int eh controller, but now i won't get the ul
如果我将
'views/collection/view-test'
'views/item/itemview-test'
int eh控制器,则可以渲染li
,但是现在我无法获得ul
also, if i console.log(new ItemviewTest())
in the collection, i can see the ItemView
object with the $el:'li'
tag, but for some reason it doesn't get added to the html 另外,如果我在集合中
console.log(new ItemviewTest())
,我可以看到带有$el:'li'
标签的ItemView
对象,但是由于某种原因,它没有被添加到html中。
any ideas? 有任何想法吗?
An ItemView
is rendered for each model in the parent CollectionView
's collection. 为父
CollectionView
的集合中的每个模型呈现一个ItemView
。 Since the collection is empty, there are no models to render. 由于集合为空,因此没有要渲染的模型。
Try adding a model: 尝试添加模型:
var collectionTest = new CollectionTest([{ name: 'Patrioticcow' }]);
App.regionTest.show(new ViewTest({
collection: collectionTest
}));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.