类似于问题21560374。
我试图实现Backbone.Paginator版本0.8,在页面加载时遇到了错误: Uncaught :无法读取未定义的属性'requestPager‘。
首先,我引用了CDNJS文件,然后下载了原始代码,并将其放在app/assets/javascripts中。我在application.js '//= Requirebackbone.paginator.min.js‘中也需要它。
下面是位于application.html.erb中的my节代码:
<head>
<title>D2jive</title>
<link href='http://fonts.googleapis.com/css?family=Audiowide' rel='stylesheet' type='text/css'>
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
<%= stylesheet_link_tag "application", media: "all" %>
<%= javascript_include_tag "application" %>
<script type="text/javascript" src="assets/backbone.paginator.min.js"></script>
<%= csrf_meta_tags %>
</head>在窗口上,我实例化我的路由器:
window.D2Jive = {
Views: {},
Routers: {},
Events: {},
Models: {},
Collections: {},
initialize: function() {
D2Jive.router = new this.Router();
Backbone.history.start({pushState: true});
},
};位于我的路由器中,我引用我的PaginatedCollection:
this.collection = new D2Jive.Collections.PaginatedCollections( [], { location: location });然后,在Backbone.Paginator.requestPager的实际代码出现的地方,会弹出错误。
D2Jive.Collections.PaginatedCollection = Backbone.Paginator.requestPager.extend({
initialize: function(attributes, options){
this.city = options.location;
},我仍然习惯于JavaScript,但是在窗口初始化函数创建了一个新的路由器并检查我创建的Backbone.Paginator集合之后,似乎正在加载Backbone.Paginator代码。我只是不知道如何避免这种情况。
错误弹出后,我可以在控制台中加载Backbone.Paginator.requestPager。
Backbone.Paginator.requestPager.extend
function (protoProps, staticProps) {
var parent = this;
var child;
// The constructor function for the new subclass is either defined by you
// (the "constructor" property in your `extend` definition), or defaulted
// by us to simply call the parent's constructor.
if (protoProps && _.has(protoProps, 'constructor')) {
child = protoProps.constructor;
} else {
child = function(){ return parent.apply(this, arguments); };
}
// Add static properties to the constructor function, if supplied.
_.extend(child, parent, staticProps);
// Set the prototype chain to inherit from `parent`, without calling
// `parent`'s constructor function.
var Surrogate = function(){ this.constructor = child; };
Surrogate.prototype = parent.prototype;
child.prototype = new Surrogate;
// Add prototype properties (instance properties) to the subclass,
// if supplied.
if (protoProps) _.extend(child.prototype, protoProps);
// Set a convenience property in case the parent's prototype is needed
// later.
child.__super__ = parent.prototype;
return child;
} 任何帮助都将不胜感激!
发布于 2014-04-10 11:29:15
在启动应用程序之前,请确保包含了主干分页程序库。错误弹出后可以访问requestPager的原因很可能是因为在这个阶段,库已经加载。
为了确保这不是代码的问题,请尝试在页面的<head>部分中包含主干分页代码。
根据评论编辑:
您需要更改"app/assets/javascripts/application.js“,以便按正确的顺序包含这些文件。类似于:
//= require jquery
//= require jquery_ujs
//= require underscore
//= require backbone
//= require bacbkone.paginator.min
//= require_tree .如果您只依赖require_tree来包含这些文件,它们就不一定按正确的顺序包含,这就是您正在体验的。
此外,由于主干分页器被包含在应用程序文件中,所以它不应该在应用程序文件中。
https://stackoverflow.com/questions/22975771
复制相似问题