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 主干.Paginator:无法读取属性';请求寻呼机';_Backbone.js_Pagination_Backbone.paginator - Fatal编程技术网

Backbone.js 主干.Paginator:无法读取属性';请求寻呼机';

Backbone.js 主干.Paginator:无法读取属性';请求寻呼机';,backbone.js,pagination,backbone.paginator,Backbone.js,Pagination,Backbone.paginator,类似于 我正在尝试实现版本0.8,在页面加载时遇到错误:UncaughtTypeError:无法读取未定义的属性'requestPager' 首先我引用了CDNJS文件,然后下载了原始代码并将其放在app/assets/javascripts中。我在application.js'/=require backbone.paginator.min.js'中也需要它 以下是位于application.html.erb中的my部分代码: <head> <title>D2jiv

类似于

我正在尝试实现版本0.8,在页面加载时遇到错误:UncaughtTypeError:无法读取未定义的属性'requestPager'

首先我引用了CDNJS文件,然后下载了原始代码并将其放在app/assets/javascripts中。我在application.js'/=require backbone.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>
位于我的路由器中,我指的是我的分页集合:

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,但它似乎是主干。Paginator代码在window initialize函数创建新路由器并检查主干后加载。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;
  } 

任何帮助都将不胜感激

启动应用程序之前,请确保包含主干分页器库。出现错误后可以访问
requestPager
的原因可能是因为在该阶段,库已经加载

为了确保代码没有问题,请尝试在页面的
部分包含主干分页器代码

根据评论进行编辑:

您需要更改“app/assets/javascripts/application.js”,使其以正确的顺序包含文件。比如:

//= require jquery
//= require jquery_ujs
//= require underscore
//= require backbone
//= require bacbkone.paginator.min
//= require_tree .
如果您仅仅依靠
require_tree
来包含文件,那么它们不一定会以正确的顺序包含,这正是您所经历的


另外,由于主干分页器包含在应用程序文件中,因此它不应再包含在应用程序文件中。

对不起,应该包含我的代码,我已编辑了上面的问题。如您所见,我在application.html.erb中引用了该文件。谢谢还是一样的错误。这一次,如果我交换行,我会得到错误“主干未定义”,因为分页器需要主干。因此,我在backbone.paginator上方添加了一行,其中添加了需要主干的application.js,然后“主干未定义”错误消失,但“无法读取未定义的属性'requestPager'错误仍然存在”。再次感谢您的帮助!是的,我忘了rails资产。。。我已经更新了我的答案:您的application.js需要以正确的顺序列出依赖项。
//= require jquery
//= require jquery_ujs
//= require underscore
//= require backbone
//= require bacbkone.paginator.min
//= require_tree .