- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
问题是,每次我通过每个元素上的集合 (MovieCollection) 的获取函数添加新对象时,都会添加某种事件触发器,并初始化一个新的 MovieList 集合在获取所有项目后传递到的对象。
这是我的 app.js:
// Global App skeleton for backbone
var App = new Backbone.Marionette.Application();
_.extend(App, {
Controller: {},
View: {},
Model: {},
Page: {},
Scrapers: {},
Providers: {},
Localization: {}
});
// set database
App.addRegions({ Window: ".main-window-region" });
App.addInitializer(function(options){
var mainWindow = new App.View.MainWindow();
try{
App.Window.show(mainWindow);
} catch(e) {
console.error("Couldn't start app: ", e, e.stack);
}
});
所以基本上我创建了如下所示的 MainWindow View :
(function(App) {
"use strict";
var MainWindow = Backbone.Marionette.LayoutView.extend({
template: "#main-window-tpl",
id: 'main-window',
regions: {
Content: '#content',
},
initialize: function() {
//Application events
//App.vent.on('movies:list', _.bind(this.showMovies, this));
},
onShow: function() {
this.showMovies();
//App.vent.trigger('main:ready');
},
showMovies: function(e) {
var browser = new App.View.MovieBrowser();
this.Content.show(browser);
}
});
App.View.MainWindow = MainWindow;
})(window.App);
这里是MovieBrowser,它应该创建集合,获取它,然后在节目中将其传递到MovieList。
(function(App) {
'use strict';
var MovieBrowser = Backbone.Marionette.LayoutView.extend({
template: '#movie-browser-tpl',
className: 'movie-browser',
regions: {
MovieList: '.movie-list-region'
},
initialize: function() {
console.log('Init MovieBrowser');
this.movieCollection = new App.Model.MovieCollection([], {});
this.movieCollection.fetch();
},
onShow: function() {
var ml = new App.View.MovieList({
collection: this.movieCollection
});
this.MovieList.show(ml);
}
});
App.View.MovieBrowser = MovieBrowser;
})(window.App);
所以反过来 MovieCollection 是(我猜一个主要问题是它的某些问题):
(function(App) {
"use strict";
var MovieCollection = Backbone.Collection.extend({
model: App.Model.Movie,
initialize: function(models, options) {
console.log('Init MovieCollection');
},
fetch: function() {
this.add([{"imdb":"1598172","title":"Once Upon a Time in Brooklyn","year":2013,"MovieRating":"4.1","image":"http://zapp.trakt.us/images/posters_movies/217035-300.jpg","bigImage":"http://zapp.trakt.us/images/posters_movies/217035-300.jpg","torrents":{"1080p":{"url":"https://yts.re/download/start/739F9B2F114DB4B48D34DEE2787725FF0747F6F3.torrent","size":"1768399511","seed":"2712","peer":"1709"},"720p":{"url":"https://yts.re/download/start/E482DC66BA1117F3706FACD0292BD32F1CDFE5F5.torrent","size":"854590014","seed":"1553","peer":"828"}},"backdrop":"http://zapp.trakt.us/images/fanart_movies/217035-940.jpg","synopsis":"After being released from prison, Bobby goes back to the mob connected streets. When forced to make a life altering decision the truth is revealed that he was too blind to see.","genres":[],"certification":"R","runtime":116,"tagline":"","trailer":""}]);
},
});
App.Model.MovieCollection = MovieCollection;
})(window.App);
而电影列表是:
(function(App) {
"use strict";
var SCROLL_MORE = 200;
var ErrorView = Backbone.Marionette.ItemView.extend({
template: '#movie-error-tpl',
onBeforeRender: function() {
this.model.set('error', this.error);
}
});
var MovieList = Backbone.Marionette.CompositeView.extend({
template: '#movie-list-tpl',
tagName: 'ul',
className: 'movie-list',
itemView: App.View.MovieItem,
itemViewContainer: '.movies',
initialize: function() {
console.log('Init MovieList')
if (typeof this.collection !== 'undefined') {
//this.listenTo(this.collection, 'loading', this.onLoading);
//this.listenTo(this.collection, 'loaded', this.onLoaded);
//this.collection.fetch();
} else {
console.trace()
}
},
});
App.View.MovieList = MovieList;
})(window.App);
这是MovieItem:
(function(App) {
"use strict";
var MovieItem = Backbone.Marionette.ItemView.extend({
template: '#movie-item-tpl',
tagName: 'li',
className: 'movie-item',
ui: {
coverImage: '.cover-image',
cover: '.cover'
}
});
App.View.MovieItem = MovieItem;
})(window.App);
最终电影模型是:
(function(App) {
"use strict";
var Movie = Backbone.Model.extend({
idAttribute: 'imdb',
initialize: function() {
},
});
App.Model.Movie = Movie;
})(window.App);
因此,为了运行它,我基本上必须检查集合是否未定义。查看它是否会继续,确实如此,但应用程序本身无法正常工作,因为它创建了多个 MovieList 项目,并添加了多个具有相同 id 的 ul 元素。
这是 html 模板:
这是 JS 文件的包含顺序:
<!-- App Initialization -->
{{ HTML::script('js/App/app.js') }}
<!-- Backbone Views and Controllers -->
{{ HTML::script('js/App/views/main_window.js') }}
{{ HTML::script('js/App/views/movie_browser/movie_browser.js') }}
{{ HTML::script('js/App/views/movie_browser/movie_item.js') }}
<!-- Backbone Models -->
{{ HTML::script('js/App/models/movie.js') }}
{{ HTML::script('js/App/models/movie_collection.js') }}
{{ HTML::script('js/App/views/movie_browser/movie_list.js') }}
我尝试将 movie_list.js 移动到几乎任何位置,但没有成功。
非常感谢任何帮助,因为这在过去 5 天里让我发疯。
鸣谢:该代码取自旧版本的 Popcorn-Time,仅供学习之用。
编辑:
显示确切错误的实时版本:
最佳答案
尝试交换 moview_browser.js
和 moview_item.js
。应首先定义 ItemView。
The default rendering mode for a CompositeView assumes a hierarchical, recursive structure. If you configure a composite view without specifying an childView, you'll get the same composite view class rendered for each child in the collection.
关于javascript - Marionette CompositeView 调用从集合中添加的每个元素,这些元素属于 CompositeView...为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26351911/
我创建了一个用户可以添加测试的字段。这一切运行顺利我只希望当用户点击(添加另一个测试)然后上一个(添加另一个测试)删除并且这个显示在新字段中。 所有运行良好的唯一问题是点击(添加另一个字段)之前添加另
String[] option = {"Adlawan", "Angeles", "Arreza", "Benenoso", "Bermas", "Brebant
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我正在努力将 jQuery 滚动功能添加到 nav-tab (Bootstrap 3)。我希望用户能够选择他们想要的选项卡,并在选项卡内容中有一个可以平滑滚动到 anchor 的链接。这是我的代码,可
我正在尝试在用户登录后再添加 2 个 ui 选项卡。首先,我尝试做一个之后。 $('#slideshow').tabs('remove', '4'); $("#slideshow ul li:last
我有一个包含选择元素的表单,我想通过选择添加和删除其中一些元素。这是html代码(这里也有jsfiddle http://jsfiddle.net/txhajy2w/):
正在写这个: view.backgroundColor = UIColor.white.withAlphaComponent(0.9) 等同于: view.backgroundColor = UICo
好的,如果其中有任何信息,我想将这些列添加到一起。所以说我有 账户 1 2 3 . 有 4 个帐户空间,但只有 3 个帐户。我如何创建 java 脚本来添加它。 最佳答案 Live Example H
我想知道是否有一种有效的预制算法来确定一组数字的和/差是否可以等于不同的数字。示例: 5、8、10、2,使用 + 或 - 等于 9。5 - 8 = -3 + 10 = 7 + 2 = 9 如果有一个预
我似乎有一个卡住的 git repo。它卡在所有基本的添加、提交命令上,git push 返回所有内容为最新的。 从其他帖子我已经完成了 git gc 和 git fsck/ 我认为基本的调试步骤是
我的 Oracle SQL 查询如下- Q1- select hca.account_number, hca.attribute3, SUM(rcl.extended_amou
我正在阅读 http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingG
我正在尝试添加一个“加载更多”按钮并限制下面的结果,这样投资组合页面中就不会同时加载 1000 个内容,如下所示:http://typesetdesign.com/portfolio/ 我对 PHP
我遇到这个问题,我添加了 8 个文本框,它工作正常,但是当我添加更多文本框(如 16 个文本框)时,它不会添加最后一个文本框。有人遇到过这个问题吗?提前致谢。 Live Link: JAVASCRIP
add/remove clone first row default not delete 添加/删除克隆第一行默认不删除&并获取正确的SrNo(例如:添加3行并在看到问题后删除SrNo.2)
我编码this ,但删除按钮不起作用。我在控制台中没有任何错误.. var counter = 0; var dataList = document.getElementById('materi
我有一个类似数组的对象: [1:数组[10]、2:数组[2]、3:数组[2]、4:数组[2]、5:数组[3]、6:数组[1]] 我正在尝试删除前两个元素,执行一些操作,然后将它们再次插入到同一位置。
使用的 Delphi 版本:2007 你好, 我有一个 Tecord 数组 TInfo = Record Name : String; Price : Integer; end; var Info
我使用了基本的 gridster 代码,然后我声明了通过按钮添加和删除小部件的函数它工作正常但是当我将调整大小功能添加到上面的代码中时,它都不起作用(我的意思是调整大小,添加和删除小部件) 我的js代
title 323 323 323 title 323 323 323 title 323 323 323 JS $(document).keydown(function(e){
我是一名优秀的程序员,十分优秀!