【问题标题】:Uncaught TypeError: undefined is not a function in simplePagination.jsUncaught TypeError: undefined is not a function in simplePagination.js
【发布时间】:2014-11-24 14:03:41
【问题描述】:

我尝试使用 js 文件在我的网页中包含分页,但它显示在浏览器控制台 TypeError: $(...).pagination is not a function 它可能有什么问题/问题? 注意:我正在使用 require.js 来加载脚本。 请重播,提前谢谢 这是我的名为 testPagination.js 的 require 模块

 define(['jquery','pagination'], function($,pagination) {
        /* GET DATASOURCE FROM HIDDEN FIELD */
        function Hello() {
            alert('helo...!!!');
        }

        function loadPagination(total)
        {
            alert("PAGINATION CALLED");
            $('#listing-paginationtest').pagination({
                items : total,
                    itemsOnPage : 10,
                    cssStyle : 'dark-theme',
                    onPageClick : function(pageNumber) {
                    }
            });
            alert("PAGINATION END");
        }

        return {
            Hello:Hello,
            loadPagination:loadPagination
        };
    });

我在 main.js 中像这样调用这个模块方法

 require.config({

        baseUrl : "js",

        paths : {

            "text" : "libs/require/plugins/text",
            "jquery" : "libs/jquery/jquery",
            "blockUI" : "libs/jquery/plugins/jquery.blockUI",
            "pagination" : "libs/jquery/plugins/jquery.simplePagination",
            "cookie" : "libs/jquery/plugins/jquery.cookie",
            "backbone" : "libs/backbone/backbone",
            "underscore" : "libs/underscore/underscore",

            // BACKBONE MODELS
            "models" : "models/models",
            "templates" : "../templates",
            "plugins" : "libs/jquery/plugins",
            "pages" : "pages",
            "util" : "modules/store/util",
            "store" : "modules/store/main",

            // MODULES
            "datasourceModule" : "modules/datasourceModule",
            "cookieModule" : "modules/cookieModule",
            "testPagination":"modules/testPagination"
            "bootstrap" : "../design/js/bootstrap.min",
        },
        waitSeconds: 200,
        shim : {

            'jquery' : {

                exports : '$'
            },

            'backbone' : {

                deps : [ 'underscore', 'jquery' ],
                exports : 'Backbone'
            },

            'underscore' : {

                exports : '_'
            },

            'models' : {

                deps : [ 'backbone' ],
            },


            'datasourceModule' : {

                deps : [ 'jquery', 'backbone', 'models' ]
            },

            'store' : {

                deps : [ 'backbone' ],
            },

            'testPagination' : {

                deps : [ 'jquery' ]
            },
            // DESIGN
            'bootstrap' : {

                deps : [ 'jquery' ]
            },

        }
    });

        function loadPageNumbers() {
            alert("Hi hi");
            require([ "jquery", "testPaginationModule"],

            function($, testPaginationModule) {
                testPaginationModule.loadPagination(1000);
            });
        }

【问题讨论】:

  • 我们怎么可能调试我们看不到的代码?
  • 我也在这里给出了代码...
  • #listing-paginationtest 在被调用时是否存在?
  • @torazaburo ,即在 div 标签中作为 id ,但是我如何检查#listing-paginationtest 在被调用时是否存在?
  • @torazaburo 元素不存在对此没有影响。给定错误与jQuery.prototype 上根本不存在的方法有关。

标签: javascript pagination jquery-pagination


【解决方案1】:

如果您使用“添加全局变量”方法的库,则需要configure RequireJS to properly handle them。否则,它们会以不确定的顺序异步加载。

requirejs.config({
    shim: {
        'jquery': {
            exports: 'jQuery'
        },
        'pagination': ['jquery']
    }
});

【讨论】:

  • github.com/flaviusmatis/simplePagination.js/blob/master/…我正在使用这个js文件进行分页
  • 谢谢,但我已经配置了那个,但仍然遇到问题
  • 我没有使用RequireJS的经验,所以我看不到任何明显的东西。尝试创建一个实时 jsfiddle/codepen 来重现问题或自己调试它(从您的 jQuerypagination 库登录到控制台,并找出它们是否完全包含以及按什么顺序包含)。
猜你喜欢
  • 2015-09-18
  • 2015-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-06
  • 2014-08-15
  • 2015-01-14
相关资源
最近更新 更多