1. <i id='P0cP7'><tr id='P0cP7'><dt id='P0cP7'><q id='P0cP7'><span id='P0cP7'><b id='P0cP7'><form id='P0cP7'><ins id='P0cP7'></ins><ul id='P0cP7'></ul><sub id='P0cP7'></sub></form><legend id='P0cP7'></legend><bdo id='P0cP7'><pre id='P0cP7'><center id='P0cP7'></center></pre></bdo></b><th id='P0cP7'></th></span></q></dt></tr></i><div id='P0cP7'><tfoot id='P0cP7'></tfoot><dl id='P0cP7'><fieldset id='P0cP7'></fieldset></dl></div>
        <legend id='P0cP7'><style id='P0cP7'><dir id='P0cP7'><q id='P0cP7'></q></dir></style></legend><tfoot id='P0cP7'></tfoot>

        <small id='P0cP7'></small><noframes id='P0cP7'>

          <bdo id='P0cP7'></bdo><ul id='P0cP7'></ul>

      2. router.js 函数未执行

        时间:2023-10-02
        <legend id='3H0cr'><style id='3H0cr'><dir id='3H0cr'><q id='3H0cr'></q></dir></style></legend>

        <small id='3H0cr'></small><noframes id='3H0cr'>

          <i id='3H0cr'><tr id='3H0cr'><dt id='3H0cr'><q id='3H0cr'><span id='3H0cr'><b id='3H0cr'><form id='3H0cr'><ins id='3H0cr'></ins><ul id='3H0cr'></ul><sub id='3H0cr'></sub></form><legend id='3H0cr'></legend><bdo id='3H0cr'><pre id='3H0cr'><center id='3H0cr'></center></pre></bdo></b><th id='3H0cr'></th></span></q></dt></tr></i><div id='3H0cr'><tfoot id='3H0cr'></tfoot><dl id='3H0cr'><fieldset id='3H0cr'></fieldset></dl></div>

            <bdo id='3H0cr'></bdo><ul id='3H0cr'></ul>
            <tfoot id='3H0cr'></tfoot>

                  <tbody id='3H0cr'></tbody>
                • 本文介绍了router.js 函数未执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  <块引用>

                  //文件名:router.jsconsole.log('测试路线');定义(['jquery','下划线','骨干','视图/工作/列表'], 函数($, _, Backbone, JobListView){var AppRouter = Backbone.Router.extend({路线:{//定义一些 URL 路由'/dalo​​/jobs': 'showJobs',//默认'*actions': 'defaultAction'}});var 初始化 = 函数(){var app_router = 新的 AppRouter;app_router.on('route:showJobs', function(){//在我们通过依赖数组加载的模块上调用渲染//'视图/工作/列表'console.log('显示作业路径');var jobListView = new JobListView();jobListView.render();});app_router.on('defaultAction', function(actions){//我们没有匹配的路由,让我们记录一下 URL 是什么console.log('No route:', actions);});Backbone.history.start();};返回 {初始化:初始化};});

                  我的 main.js 的一部分,我没有使用 NEW,因为它给出了一个问题,说它不是一个函数,不确定它是否与上面的错误有关

                  require(['app'], function(AppView){AppView.initialize();});

                  我在 Router.initialize() 之后做了一个 console.Log;在 app.js ,它可以显示.我还在这个应用程序 router.js 上面一直做了一个控制台日志,它也显示,除此之外,它没有显示函数内部的任何内容.

                  控制台只显示 2 个控制台日志(在 Route.Initialize 之后 & 在 router.js 定义之前

                  有什么建议吗?我正在使用 http://backbonetutorials.com/organizing-backbone-using-modules/

                  我的 App.js

                  define(['jquery','下划线','骨干','router',//请求 router.js], 函数($, _, Backbone, Router){var 初始化 = 函数(){//传入我们的路由器模块并调用它的初始化函数路由器初始化();console.log('路由器初始化');}返回 {初始化:初始化};});

                  解决方案

                  可能您使用的是 非 AMD 版本的 Backbone.js 和 Underscore.js.

                  通过这种方式,您必须将所谓的垫片"添加到您的主/配置文件中.

                  <块引用>

                  shim:为较旧的传统浏览器全局变量"脚本配置依赖项、导出和自定义初始化,这些脚本不使用 define() 来声明依赖项并设置模块值.http://requirejs.org/docs/api.html#config-shim

                  正如您所看到的,设置依赖项并导出您的库,以便您在脚本中使用它.

                  因此,在您的主/配置文件中,在路径之后尝试添加此垫片部分:

                  路径:{...},垫片:{'主干':{deps: ['jquery','underscore'],出口:骨干"}}

                  现在我想你可以继续......

                  // Filename: router.js
                  console.log('TEST ROUTE');
                  define([
                      'jquery',
                      'underscore',
                      'backbone',
                      'views/jobs/list'
                  ], function($, _, Backbone, JobListView){
                      var AppRouter = Backbone.Router.extend({
                          routes: {
                              // Define some URL routes
                              '/dalo/jobs': 'showJobs',
                  
                              // Default
                              '*actions': 'defaultAction'
                          }
                      });
                  
                      var initialize = function(){
                          var app_router = new AppRouter;
                          app_router.on('route:showJobs', function(){
                              // Call render on the module we loaded in via the dependency array
                              // 'views/jobs/list'
                              console.log('Show Job Route');
                              var jobListView = new JobListView();
                              jobListView.render();
                  
                          });
                  
                          app_router.on('defaultAction', function(actions){
                              // We have no matching route, lets just log what the URL was
                              console.log('No route:', actions);
                          });
                          Backbone.history.start();
                      };
                      return {
                          initialize: initialize
                      };
                  });
                  

                  Part of my main.js , i didnt use NEW because it gave issues saying it's not a function not sure if it's related to the error above

                  require(['app'], function(AppView){
                      AppView.initialize();
                  });
                  

                  I did a console.Log after Router.initialize(); at app.js , it can show. I also did a console log all the way above in this app router.js it's also showing, other than that , it doesnt show anything inside the function.

                  The console is only showing that 2 console Log (After Route.Initialize & Before router.js define

                  Any advice? I'm using http://backbonetutorials.com/organizing-backbone-using-modules/

                  My App.js

                  define([
                      'jquery',
                      'underscore',
                      'backbone',
                      'router', // Request router.js
                  ], function($, _, Backbone, Router){
                      var initialize = function(){
                          // Pass in our Router module and call it's initialize function
                          Router.initialize();
                          console.log('Router Initialized');
                      }
                  
                      return {
                          initialize: initialize
                      };
                  });
                  

                  解决方案

                  Probably you're using a non-AMD version of Backbone.js and Underscore.js.

                  This way you've to add what it's called a "shim" to your main/config file.

                  shim: Configure the dependencies, exports, and custom initialization for older, traditional "browser globals" scripts that do not use define() to declare the dependencies and set a module value. http://requirejs.org/docs/api.html#config-shim

                  As you can see this set dependencies and export your lib in order to let you using it in your scripts.

                  So, in your main/config file, after the paths try adding this shim part:

                  paths: {
                      ...
                  },
                  shim: {
                      'backbone': {
                          deps: ['jquery','underscore'],
                          exports: 'Backbone'
                      }
                  }   
                  

                  Now I suppose you could proceed ...

                  这篇关于router.js 函数未执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Backbone.js 如何与 PHP 一起使用 下一篇:如何通过 Slim php 和 Paris 将主干模型数据发布到数

                  相关文章

                  最新文章

                • <small id='npCAJ'></small><noframes id='npCAJ'>

                  <i id='npCAJ'><tr id='npCAJ'><dt id='npCAJ'><q id='npCAJ'><span id='npCAJ'><b id='npCAJ'><form id='npCAJ'><ins id='npCAJ'></ins><ul id='npCAJ'></ul><sub id='npCAJ'></sub></form><legend id='npCAJ'></legend><bdo id='npCAJ'><pre id='npCAJ'><center id='npCAJ'></center></pre></bdo></b><th id='npCAJ'></th></span></q></dt></tr></i><div id='npCAJ'><tfoot id='npCAJ'></tfoot><dl id='npCAJ'><fieldset id='npCAJ'></fieldset></dl></div>
                  <tfoot id='npCAJ'></tfoot>

                      <bdo id='npCAJ'></bdo><ul id='npCAJ'></ul>

                    1. <legend id='npCAJ'><style id='npCAJ'><dir id='npCAJ'><q id='npCAJ'></q></dir></style></legend>