Tag: requirejs

数据表Bootstrap主题在使用ReactJS时不适用

我是RequireJS的新手,所以请保持温柔! 下面是我的HTML和JS的链接,如果你运行它,你会看到数据表已正确初始化,但它没有应用bootstrap主题。 链接问题: https://jsfiddle.net/sajjansarkar/c2f7s2jz/2/ 我究竟做错了什么? 下面是我的JS(如果小提琴不起作用): requirejs.config({ paths: { ‘jquery’: ‘https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery’, ‘bootstrap’: ‘https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min’, ‘datatables’: ‘https://cdn.datatables.net/v/bs/dt-1.10.12/b-1.2.2/b-colvis-1.2.2/b-html5-1.2.2/cr-1.3.2/fh-3.1.2/kt-2.1.3/r-2.1.0/sc-1.4.2/se-1.2.0/datatables.min’, }, shim: { ‘bootstrap’: { deps: [‘jquery’] }, ‘datatables’: [‘jquery’, ‘bootstrap’], } }); require([ ‘jquery’, ‘bootstrap’, , ‘datatables’ ], function($, Bootstrap, datatables) { ‘use strict’; $(‘#example’).dataTable(); }); HTML: Name Position Office Age Start date Salary Tiger Nixon System Architect Edinburgh […]

RequireJS,jquery仍未定义

我知道这已经讨论过了,但是经过一段时间的搜索,我无法弄清楚为什么我的小设置没有正确地用requireJS加载jquery。 我正在从’file://’运行一个小样本html页面并尝试通过调用require来加载2个模块: jQuery的 我写的一个自定义模块 如果我的自定义模块正确加载(我可以在require调用中使用它的别名,jquery总是未定义) 我试图在require.config中设置路径,以及shim(导出’$’或’jQuery’),但它不起作用。 我可以让jquery正确加载的唯一方法是删除所有路径定义并命名我的文件系统’jquery.js’上的jquery文件 这是我的配置: main.js: require.config({ baseUrl: ‘scripts’, paths: { jquery: ‘jquery-2.1.3.min’ //does not work //jquery: ‘http://code.jquery.com/jquery-2.1.3.min.js’ //does not work either } }); console.log( “main.js is loaded” ); //this is correctly ouputed to the console 的test.html: require( [‘jquery’,’custom’], function($, Custom){ console.info(‘$:’); console.info($); //outputs undefined console.info(‘Custom:’); console.info(Custom); //outputs my custom object }); […]

Angular + Requirejs – 加载顺序错误

我正在尝试使用requirejs加载angular和jquery。 我能做的最好的是,50%的时间都能正确加载,另一半我收到错误No Module: mainApp 我假设这根据requirejs异步加载脚本的速度打破了一半的时间。 当它工作时,我看到“Hello World”测试(虽然我确实看到{{text}}在替换之前闪存,但我一直在阅读如何解决这个问题)。 剩下的时间我收到错误并且{{text}}只停留在屏幕上。 Github Repo Tree: index.html – js – libs require.js – modules mainApp.js main.js main.js require.config({ paths: { ‘jQuery’: ‘//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min’, ‘angular’: ‘//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular’, }, shim: { ‘angular’ : {‘exports’ : ‘angular’}, ‘jQuery’: {‘exports’ : ‘jQuery’} } }); require([‘jQuery’, ‘angular’, ‘modules/mainApp’] , function ($, angular, mainApp) { $(function () { […]

使用带有RequireJS的私有jquery – 优化后发出问题

我正在使用requireJS和一个CDN版本的jQuery(现在是推荐的方法)组合一个框架,并在优化代码时遇到一些问题。 输出是命名空间的,我指定每个模块使用文档中概述的jquery的私有版本: require.config({ // Add this map config in addition to any baseUrl or // paths config you may already have in the project. map: { // ‘*’ means all modules will get ‘jquery-private’ // for their ‘jquery’ dependency. ‘*’: { ‘jquery’: ‘jquery-private’ }, // ‘jquery-private’ wants the real jQuery module // though. If this […]

jquery,bootstrap 3.0和requirejs。 不能使用bootstrap的function

我查看了与此问题相关的所有信息(确定..第一次google网页点击),但解决方案无效。 我的config.js如下所示: var config = { paths : { jquery : “//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min”, // “jquery” : “momsplanner/backgrid/assets/js/jquery”, “underscore” : “momsplanner/underscore/underscore”, “text” : “momsplanner/requirejs_text/text”, // “backbone” : “momsplanner/backbone”, “Backbone” : “momsplanner/backgird/assets/js/backbone”, “Backgrid” : “momsplanner/backgrid/lib/backgrid”, “bootstrap” : “momsplanner/bootstrap/dist/js/bootstrap” // “bootstrap” : “//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/js/bootstrap” // ‘jquery.bootstrap’ : “momsplanner/backgrid/assets/js/bootstrap” }, // A lot of dependencies don’t support AMD loaders. Here is […]

RequireJS – 具有多个jQuery版本的jQuery插件

我试图在模块中包装一些遗留的js代码,以便可以使用RequireJS加载它们。 我有三个jQuery插件,我们称之为a,b和c。 插件适用于任何版本的jQuery 插件b适用于jQuery版本1.4.2 插件c使用a和b,并适用于任何版本的jQuery。 因此,只要需要插件a,需要加载的jQuery就是版本1.4.2。 我的require.config看起来像: require.config({ paths:{ “jquery”: “libs/jquery.1.9.1.min”, “jquery1-4-2” : “libs/jquery1.4.2.min” }); 插件定义如下: plugin a: define([“jquery”], function($){ (…) }); plugin b: define([“jquery1-4-2”], function($){ (…) }); plugin c: define([“jquery”, “a”,”b”], function($){ (…) }); 如何配置此方案,以便如果任何插件需要某个版本的jQuery,而其他插件不需要版本,那么只加载某个版本? 提前致谢。

如何使用Require.js实现TinyMCE?

我目前正在将TinyMCE源作为依赖项传递,然后调用tinyMCE.init({}); 但它没有初始化TinyMCE。 当我在console.log TinyMCE时,它返回一个TinyMCE对象。 代码示例如下: define([ ‘jQuery’, ‘Underscore’, ‘Backbone’, ‘TinyMCE’ ], function($, _, Backbone, tinyMCE) { tinyMCE.init({ mode: “exact”, elements: $(‘textarea’), theme: “advanced”, theme_advanced_toolbar_location: ‘top’, theme_advanced_buttons1: ‘bold,italic,underline,bullist,numlist,link,unlink’, theme_advanced_buttons2: ”, theme_advanced_buttons3: ”, theme_advanced_toolbar_align: ‘left’, plugins: ‘paste,inlinepopups’, width: ‘100%’, height: textarea.attr(‘data-height’), oninit: function () { console.log(‘TargetTD :’); console.log(targetTD); } }); } });

如何在IE8中触发自定义javascript事件?

我试图在IE8上发起一个自定义事件,并从这里和这里一起摆弄一个解决方案。 但我不能让它工作…… 我正在使用带有requireJS和谷歌分析的jquery mobile。 所以我正在跟踪JQM pageshow事件。 但是由于requireJS加载脚本async,我对pageshow的绑定需要在javascript“包装器”中进行,否则会产生错误,因为在解析代码片段时,jquery和jquery mobile都不会被加载。 所以我在每个页面的末尾都包含这个: if (document.addEventListener) { document.addEventListener(“jqmReady”,function(){trigAnalytics(“jqmReady”);alert(“FF detected”)},false); } else if ( document.attachEvent ) { document.attachEvent(“jqmReady”, function(){trigAnalytics(“jqmReady”);alert(“IE detected”)}); } 当检测到时,我正在使用pageshow绑定触发我的分析代码段: var trigAnalytics = function( trigger ){ $(document).on(‘pageshow’,’div:jqmData(role=”page”).basePage’, function (event, ui) { var url = location.href; try { hash = location.hash; if (hash && hash.length > 1) { _gaq.push([‘_trackPageview’, hash.substr(1)]); […]

使用require js加载jquery插件

我是新手,需要js,问题是我真的不明白如何加载jQuery插件。 我想加载多个插件,但我已经遇到了第一个问题,选择了插件 JS //site full url var siteUrl = window.location.protocol+”//”+window.location.host + “/”; requirejs.config({ baseUrl: siteUrl + “assets/js”, paths: { “jquery”: “libs/jquery”, “jquery-ui”: “libs/jquery-ui”, “bootstrap”: “libs/bootstrap”, “scripts”: “scripts”, “plugins”: “plugins”, }, }); requirejs([‘jquery’, ‘jquery-ui’, ‘bootstrap’, ‘plugins/chosen’], function($, chosen){ $(‘.chzn-select’).chosen(); }); 我的测试HTML Test Test Test 当我尝试加载它时,我收到以下错误 TypeError: $ is not a function …tion(){“in”==self.hoverState&&self.show()},self.options.delay.show),void 0):self… bootstrap.js (line 6) […]

RequireJS + Backbone + jQuery通过`script`加载干扰通过RequireJS加载的jQuery

我刚刚尝试升级到Backbone 1.1.2,并且一直遇到jQuery问题。 默认情况下,Backbone希望在基本目录中找到jQuery为./jquery.js 。 当我将它添加到RequireJS路径并将其作为Backbone的依赖项添加到垫片时,所有内容都在require内部工作,但在外部,没有任何作用。 就好像我正在创建的本地引用是在重写全局包含的jQuery? 在我的html页面中,我有这个: homepage.js (目前有效)看起来像这样: require.config({ baseUrl: “./js”, paths: { Underscore: ‘lib/underscore/1.6.0/underscore-min’, Backbone: ‘lib/backbone/1.0.0/backbone-min’ // ,jquery: ‘lib/jquery/2.0.2/jquery.min’ // ,jqueryui: ‘lib/jqueryui/1.10.3/jquery-ui.min’ }, shim: { // ‘jqueryui’: { // deps: [‘jquery’], // exports: “$” // }, ‘Underscore’: { // deps: [‘jquery’], exports: “_” }, ‘Backbone’: { deps: [‘Underscore’, /*’jquery’*/], exports: ‘Backbone’ } } […]