私はBackbone Marionettes CollectionViewを使用しています。私はコレクションがロードされていることを指示しようとしているので、loadViewを表示するためにemptyViewを使用しています。バックボーンMarionette:読み込みにemptyViewを使用
ただし、コレクションが空の場合があり、壊れたローダーになることがあるため、これは悪いロジックです。
私はこのスクリプトを使用してみましたが、それは仕事をdidntの:https://github.com/surevine/marionette-loadingview-plugin
誰もがよりよい解決策を持っていますか?現在のコードは次のとおりです:
//loadingview
define(["marionette", "text!app/templates/loading.html"], function(Marionette, Template) {
"use strict";
return Backbone.Marionette.ItemView.extend({
template: Template
});
})
//collection
define(["marionette", "text!app/templates/events/collection.html", "app/collections/events", "app/views/events/item", 'app/views/loading'], function (Marionette, Template, Collection, Row, LoadingView) {
"use strict"
return Backbone.Marionette.CompositeView.extend({
template: Template,
itemView: Row,
itemViewContainer: "ul",
emptyView: LoadingView,
initialize: function() {
this.collection = new Collection()
return this.collection.fetch()
}
})
})
//item
define(["marionette", "text!app/templates/events/item.html"], function(Marionette, Template) {
"use strict";
return Backbone.Marionette.ItemView.extend({
template: Template,
tagName: "li"
})
})
フム、私は本当にこのソリューションのように、私はされるCollectionEventsを思ういけない:{ '要求が' 正しいです。 syncは呼び出されますが、要求は行いません。 – azz0r
あなたのビューをレンダリングした後に 'fetch'メソッドを呼び出すことで、それを修正することができます。次に例を示します。 'view = new View(); $( 'body')。append(view.render()。el); view.collection.fetch() ' – gbsice
これは面倒で、直接のDOM操作とすべての操作を伴います – azz0r