Tag: requirejs

没有方法’获得’骨干模型保存

我正在使用骨干来制作一个相当复杂的forms。 我有许多嵌套模型,并且一直在计算父模型中的其他变量,如下所示: // INSIDE PARENT MODEL computedValue: function () { var value = this.get(‘childModel’).get(‘childModelProperty’); return value; } 这似乎可以很好地保持我的UI同步,但一旦我打电话 .save() 在父模型上,我得到: Uncaught TypeError: Object # has no method ‘get’ 似乎儿童模型暂时停止响应。 我在做一些内在错误的事情吗? 编辑:堆栈跟踪是: Uncaught TypeError: Object # has no method ‘get’ publish.js:90 Backbone.Model.extend.neutralDivisionComputer publish.js:90 Backbone.Model.extend.setNeutralComputed publish.js:39 Backbone.Events.trigger backbone.js:163 _.extend.change backbone.js:473 _.extend.set backbone.js:314 _.extend.save.options.success backbone.js:385 f.Callbacks.o jquery.min.js:2 f.Callbacks.p.fireWith […]

要求js从cdn加载脚本失败

我是RequireJS的新手,由于某种原因我无法通过CDN加载脚本。 我的代码: // site full url var siteUrl = window.location.protocol+”//”+window.location.host + “/fresh/”; // requirejs config requirejs.config({ baseUrl: siteUrl + “assets/js/”, paths: { “plugins”: “plugins”, “scripts”: “scripts”, “jquery”: “https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min”, “jquery-ui”: “https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/jquery-ui.min”, “bootstrap”: “https://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/js/bootstrap.min”, } }); require([‘jquery’, ‘jquery-ui’, ‘bootstrap’, ‘plugins/chosen’], function($, chosen){ /* loading global selectors and variables */ //chosen for select boxes $(“.chzn-select”).chosen(); }); 和jquery无法加载。 我收到以下错误: […]

requirejs:模块名称“下划线”尚未加载上下文

当我刚刚加载我的应用程序时,我总是收到此错误, Error: Module name “underscore” has not been loaded yet for context: _. Use require([]) http://requirejs.org/docs/errors.html#notloaded …,h){c=Error(c+”\nhttp://requirejs.org/docs/errors.html#”+b);c.requireType=b;c.re… require.js (line 8) TypeError: Backbone.Model is undefined var ProjectModel = Backbone.Model.extend({ 但是当我点击浏览器上的刷新按钮时它们就消失了。 有谁知道为什么? 我该如何解决? 这是我的config / main / entry js文件, require.config({ //By default load any module IDs from js/lib baseUrl: ‘js’, paths: { jquery: ‘lib/jquery/jquery-min’, underscore: ‘lib/underscore/underscore-min’, backbone: […]

bootstrap-datepicker没有使用requirejs进行填充

我正在使用backbone.js + require.js构建一个应用程序。 我想在我的应用程序中使用datepicker: datepicker 由于它的非AMD,我在这样的requirejs中填充它: require.config({ baseUrl: “appjs”, paths:{ jquery: ‘../layout_assets/assets/js/libs/jquery-1.8.2.min’, dt: ‘../layout_assets/plugins/datatables/jquery.dataTables.min’, dtPlugins:’../layout_assets/plugins/datatables/dtplugins’, dtBootstrap: ‘../layout_assets/plugins/datatables/dataTables.bootstrap’, underscore: ‘../assets/js/underscore-min’, Backbone: ‘../assets/js/backbone-min’, bootstrap: ‘../assets/js/bootstrap.min’, datepicker:’../layout_assets/bootstrap-datepicker’ }, shim: { underscore:{ exports:”_” }, Backbone:{ deps: [‘underscore’,’jquery’], exports: “Backbone” }, dt: { deps:[‘jquery’], exports: “dt” }, dtPlugins: { deps:[‘jquery’,’dt’], exports:”dtPlugins” }, bootstrap: { deps:[‘jquery’], exports:”bootstrap” }, dtBootstrap: { deps: […]

如何使用require.js加载带有noConflict的jQuery

我试图通过使用require在noConflict模式下加载jquery require.config({ paths: { ‘jquery’: ‘libs/jquery-req’, underscore: ‘libs/underscore’, backbone: ‘libs/backbone’ }, shim: { jquery: { init: function() { console.log(‘jq init’); var jq = this.jQuery.noConflict(true); jq.support.cors = true; return jq; }, exports: ‘$’ }, backbone: { deps: [‘underscore’, ‘jquery’], init: function() { console.log(‘b init’); }, exports: ‘Backbone’ }, underscore: { exports: ‘_’ } } }); 并使用它: […]

需要在不同文件中配置

我正在使用requirejs。 我的main.js内容如下。 requirejs.config({ async: true, parseOnLoad: true, packages: [], paths: { jquery: ‘https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min’ } }); require([“login”], function (loginService) { loginService.login(‘validUser’); }); 现在,我的配置元素很少。 但是稍后,我将添加包,路径和其他,因此require.config行将增加。 我想将require.config作为一个不同的文件分开并使用它? 如果jquery加载延迟,是否会发生错误? 我的其他javascript文件正在使用它。

jquery / jqueryui / jquerymobile在backbone.js应用程序中加载速度不够快

本地应用程序运行良好,一旦它在服务器上大约50%的时间jquery库加载速度不够快,应用程序会抛出一堆未定义的js错误,因为任何jquery相关。 我使用的是带有jquery,jquery mobile,jquery ui和required.js的backbone.js。 require js文件看起来是否正确,或者有没有办法在启动应用程序之前判断脚本是否已加载? require.config({ paths: { jquery: ‘libs/jquery/jquery-1.7.2’, ‘jquery.ui’:’libs/jquery-ui/jquery-ui-1.8.14.custom’, ‘jquery.mobile-config’: ‘libs/jqm/jquery.mobile-config’, ‘jquery.mobile’: ‘libs/jqm/jquery.mobile-1.1.1’, underscore: ‘libs/underscore/underscore-1.3.3’, backbone: ‘libs/backbone/backbone-amd-0.9.2’, text: ‘libs/require/text’, templates: ‘../templates’ }, shim: { ‘underscore’: { exports: “_” }, ‘backbone’: { deps: [‘jquery’,’underscore’], exports: ‘Backbone’ }, ‘jquery.ui’: { deps:[‘jquery’] }, ‘jquery.mobile-config’: { deps: [‘jquery’] }, ‘jquery.mobile’: { deps:[‘jquery’,’jquery.mobile-config’] }, ‘bundles’: { deps:[‘jquery’,’jquery.mobile’,’validate’,’jquery.ui’] […]

在Require.js中使用多个版本的jQuery

我有一种情况,我必须在同一页面上运行两个版本的jQuery(基本上,有一个运行1.4.2的网站,我有一个运行需要1.8.2的脚本的书签我知道这不是一个好主意但我现在一直坚持下去。 现有版本为1.4.2合一,所需的较新版本为1.8.2。 我正在使用require.js,并在这里看到了这个问题的post,但不太明白什么是最好的方法: 在我的情况下,我有一个模块main.js: (function () { var root = this; require.config({ baseUrl: “http://localhost:9185/scripts/app/” }); define3rdPartyModules(); loadPluginsAndBoot(); function define3rdPartyModules() { define(‘jquery’, [], function () { return root.jQuery.noConflict(true); }); define(‘ko’, [], function () { return root.ko; }); } function loadPluginsAndBoot() { requirejs([], boot); } function boot() { require([‘bootStrapper’], function (bs) { bs.run(); }); } })(); 然后是一些看起来类似的模块: […]

理解requirejs路径

使用requirejs我的main.js看起来像这样 requirejs.config({ baseUrl: ‘/javascript/’, paths: { jquery: ‘http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min’, async: ‘requirePlugins/async’, hbs: ‘hbs’ }, waitSeconds: 7 }); define([‘common’], function () { loadFonts(); }); main.js包含在脚本调用的页面中 Common是网站的基本function,jquery doc ready函数等包含在define调用中: define([‘jquery’], function() { //jQuery dependant common code }); 这很好用,从谷歌CDN加载jQuery并执行代码。 但是当我在加载main.js之后添加一个require调用时 require([‘jquery’], function ($) { //code }); 从/javascript/jquery.js请求jquery而不是google cdn的已定义路径。 我仍然是requirejs的新手,但在我看来,在任何其他请求被解雇之前应该定义路径,有人可以帮助我理解我做错了什么吗?

RequireJS:问题包括优化后的jquery缓动包

我想将jquery缓动包包含到我的应用程序中。 在requireJS文件被“优化”之前,它可以正常工作。 现在我使用优化版本,当我调用使用缓动的动画时,我收到此错误: “jQuery.easing [jQuery.easing.def]不是函数”(firefox) “未捕获的TypeError:对象#的属性’未定义’不是函数”(chrome) 我像这样包括我的JS: 我的主要JS页面如下所示: http : //thebeer.co/js/built/mesh-built.js require([“globals”,”functionBank”],function(gb,r){ //myapp code }); 全局变量看起来像这样: http://thebeer.co/js/globals.js 和functionbank看起来像这样: http://thebeer.co/js/functionBank.js 我唯一的想法是,因为jQuery被声明为全局变量和函数中的依赖,它是以某种方式传递而没有附加缓动包? 我应该在主要的requireJS文件中附加缓动插件吗? FORGOT TO MENTION: 只有在requireJS对脚本进行优化后才会出现此问题…