gpt4 book ai didi

javascript - 主干没有用 require js 定义

转载 作者:行者123 更新时间:2023-11-29 16:15:45 28 4
gpt4 key购买 nike

我收到以下代码的模型未定义错误。我添加了下划线、jquery、backbone 等,但我只能通过 console.log 函数返回对象,仅用于 jquery $

是否有其他对象没有在 define 函数中返回的原因?

下面是我在 main.js 中的代码:

require.config({
paths: {
jquery: '//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min',
underscore: '//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min',
backbone: '//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min',
bootstrap: '//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min',
qunit: '//cdnjs.cloudflare.com/ajax/libs/qunit/1.11.0/qunit.min',
bootstrapDatepicker: '/js/bootstrap-datepicker',
backboneValidation: '//cdnjs.cloudflare.com/ajax/libs/backbone.validation/0.7.1/backbone-validation-min'
}

});

define([
'jquery',
'underscore',
'backbone',
'bootstrap',
'qunit',
'bootstrapDatepicker',
'backboneValidation'
], function($, _, Backbone, Bootstrap, Qunit, Datepicker, backboneValidation){

$(function(){

var ReportModel = Backbone.Model.extend({
validation: {
'date.from': {
required: true,
msg: 'Please enter a from date'
},
'date.to': {
required: true,
msg: 'Please enter a to date'
}
},
initialize: function(){
console.log('test');
}
});

$('#dp3').datepicker().on('changeDate', function(e){
$('#toDate').datepicker('setStartDate', new Date(e.date.valueOf()));
});
$('#dp4').datepicker().on('changeDate', function(e){
$('#fromDate').datepicker('setEndDate', new Date(e.date.valueOf()));
});

});
});

最佳答案

使用垫片配置:http://requirejs.org/docs/api.html#config-shim .示例:

requirejs.config({
paths: {
jquery: '//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.2/jquery.min',
underscore: '//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min',
backbone: '//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min',
},
shim: {
backbone: {
//These script dependencies should be loaded before loading backbone.js
deps: ['underscore', 'jquery'],
//Once loaded, use the global 'Backbone' as the module value.
exports: 'Backbone'
},
underscore: {
exports: '_'
},
}
});

关于javascript - 主干没有用 require js 定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16410322/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com