我无法让文本插件在Internet Explorer上使用requirejs。
我收到以下错误:
SCRIPT5: Access is denied.
text.js, line 267 character 13
几秒钟后,我收到以下错误:
SCRIPT5022: Load timeout for modules: underscore,backbone,text!templates/userListTemplate.html_unnormalized2,text!templates/editUserTemplate.html_unnormalized3,text!templates/userListTemplate.html
http://requirejs.org/docs/errors.html#timeout
require.js, line 8 character 105
我在本地加载文件,该脚本适用于Firefox和Chrome。
这是我的配置:
// file: main.js
require.config({
paths: {
"jquery" : "libs/jquery",
"underscore" : "libs/underscore",
"backbone" : "libs/backbone",
"text" : "libs/text"
},
shim: {
underscore: {
exports: '_'
},
backbone: {
deps: ["underscore", "jquery"],
exports: "Backbone"
},
text : {
exports : 'text'
}
}
});
require(['app'], function (App) {
App.initialize();
});
以下是app.js的内容:
// file: js/app.js
define([
'jquery',
'underscore',
'backbone',
'router',
'models/user',
'collections/users'
], function ($, _, Backbone, Router, User, Users) {
var initialize = function () {
// Models to populate the global collection with default values.
var user1 = new User({
firstName : 'Sassy',
lastName : 'The fancy Pussycat'
});
var user2 = new User({
firstName : 'Lola',
lastName : 'The lovable Saint Bernard'
});
var user3 = new User({
firstName : 'Dany',
lastName : 'The guy'
});
var user4 = new User({
firstName : 'Aly',
lastName : 'The cute wife'
});
var user5 = new User({
firstName : 'Last',
lastName : 'Hoping to be the first'
});
// Global collection.
window.users = new Users([user1, user2, user3, user4, user5]);
Router.initialize();
}
return {
initialize : initialize
}
});
接下来,我加载router.js:
// file: router.js
define([
'jquery',
'underscore',
'backbone',
'views/userList',
'views/editUser'
], function ($, _, Backbone, UserList, EditUser) {
var Router = Backbone.Router.extend({
routes: {
'' : 'home',
'new' : 'editUser'
}
});
var initialize = function () {
var router = new Router();
router.on('route:home', function () {
var userList = new UserList();
userList.render();
});
router.on('route:editUser', function () {
var editUser = new EditUser();
editUser.render();
});
Backbone.history.start();
}
return {
initialize : initialize
}
});
最后,这是我的观点之一:
// file: views/userList.js
define([
'jquery',
'underscore',
'backbone',
'text!templates/userListTemplate.html'
], function ($, _, Backbone, userListTemplate) {
var UserList = Backbone.View.extend({
el : '.page',
preLoader : '.preLoader',
render : function (currentPage) {
var that = this,
models = users.models,
perPage = 2,
totalPages = Math.ceil(models.length / perPage);
if (currentPage == null || currentPage.length === 0) {
currentPage = 0;
}
var start = currentPage * perPage,
end = start + perPage;
var subset = _.filter(models, function (num, index) {
return (index >= start) && (index < end);
});
var template = _.template(userListTemplate, {
users : subset,
totalPages : totalPages,
currentPage : currentPage
});
setTimeout(function () {
that.$el.append(template);
$(that.preLoader).hide();
that.$el.show('slow');
}, 500);
},
events : {
'click .pagination a' : 'click'
},
click : function (e) {
var currentPage = $(e.target).html() - 1;
this.render(currentPage);
}
});
return UserList;
});
我做错了什么?
答案 0 :(得分:1)
尝试to run local scripts on it时,Internet Explorer往往会非常简单。话虽这么说,看起来你的结果并没有什么不对,当你把一切都移到服务器上时,问题应该自行解决。在此之前,请尝试将其添加到源html的顶部:
<!-- saved from url=(0014)about:internet -->
并浏览网页,了解如何让IE接受您的本地脚本,例如this post here。