- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我遇到了这个问题:
Uncaught TypeError: Cannot call method 'replace' of undefined underscore.js:5
j.template underscore.js:5
Backbone.View.extend.render LoginView.js:13
Backbone.Router.extend.index routes.js:24
i.extend.execute backbone.js:1
(anonymous function) backbone.js:1
(anonymous function) backbone.js:1
j.some.j.any underscore.js:5
i.extend.loadUrl backbone.js:1
i.extend.start backbone.js:1
_public.start application.js:18
(anonymous function) main.js:32
i.execCb require.js:29
$.check require.js:18
(anonymous function) require.js:23
(anonymous function) require.js:8
(anonymous function) require.js:23
v require.js:7
$.emit require.js:23
$.check require.js:19
(anonymous function) require.js:23
(anonymous function) require.js:8
(anonymous function) require.js:23
v require.js:7
$.emit require.js:23
$.check require.js:19
(anonymous function) require.js:23
(anonymous function) require.js:8
(anonymous function) require.js:23
v require.js:7
$.emit require.js:23
$.check require.js:19
(anonymous function) require.js:23
(anonymous function) require.js:8
(anonymous function) require.js:23
v require.js:7
$.emit require.js:23
$.check require.js:19
(anonymous function) require.js:23
(anonymous function) require.js:8
(anonymous function) require.js:23
v require.js:7
$.emit require.js:23
$.check require.js:19
$.enable require.js:23
$.init require.js:17
E require.js:14
i.completeLoad require.js:28
i.onScriptLoad require.js:29
当我将模板分成不同的文件时。这是我的项目结构:
`-- [ 548,855] .
|-- [ 375,907] js
| |-- [ 26,085] pages
| | `-- [ 26,085] RestaurantPage
| | |-- [ 3,595] script.js
| | |-- [ 15,816] templates
| | | |-- [ 1,009] LoginTemplate.html
| | | |-- [ 2,335] edit_order.html
| | | |-- [ 3,604] AdminTemplate.html
| | | |-- [ 2,242] WaiterTemplate.html
| | | |-- [ 2,076] orders.html
| | | |-- [ 0] README
| | | `-- [ 4,550] CookerTemplate.html
| | |-- [ 1,023] routers
| | | |-- [ 1,023] routes.js
| | | `-- [ 0] README
| | |-- [ 436] models
| | | |-- [ 0] model_orders.js
| | | |-- [ 0] model_edit_order.js
| | | |-- [ 0] README
| | | `-- [ 436] User.js
| | |-- [ 4,786] views
| | | |-- [ 1,345] orders.js
| | | |-- [ 450] WaiterView.js
| | | |-- [ 1,553] AdminView.js
| | | |-- [ 546] LoginView.js
| | | |-- [ 0] edit_order.js
| | | |-- [ 0] README
| | | `-- [ 892] CookerView.js
| | `-- [ 429] collections
| | |-- [ 103] dishescollection.js
| | |-- [ 0] collections_orders.js
| | |-- [ 0] README
| | |-- [ 111] categoriescollection.js
| | |-- [ 0] collections_edit_order.js
| | `-- [ 215] UsersCollection.js
| |-- [ 834] main.js
| |-- [ 518] application.js
| `-- [ 348,470] libs
| |-- [ 14,682] underscorejs
| | `-- [ 14,682] underscore.js
| |-- [ 282,944] jquery
| | `-- [ 282,944] jquery.js
| |-- [ 30,845] requirejs
| | |-- [ 15,234] require.js
| | `-- [ 15,611] text.js
| `-- [ 19,999] backbonejs
| `-- [ 19,999] backbone.js
`-- [ 172,948] css
|-- [ 172,806] gumby.css
`-- [ 142] style.css
这是代码:main.js
'use strict';
require.config({
shim: {
underscore: {
exports: '_'
},
backbone: {
deps: [
'underscore',
'jquery'
],
exports: 'Backbone'
}
},
paths: {
jquery: 'libs/jquery/jquery',
backbone: 'libs/backbonejs/backbone',
underscore: 'libs/underscorejs/underscore',
text: 'libs/requirejs/text',
templates: 'pages/RestaurantPage/templates',
views: 'pages/RestaurantPage/views',
collections: 'pages/RestaurantPage/collections',
models: 'pages/RestaurantPage/models',
routers: 'pages/RestaurantPage/routers',
application: 'application'
}
});
require(["application"],
function(application) {
application.start();
}
);
application.js
define([
"pages/RestaurantPage/routers/routes"
//"pages/RestaurantPage/collections/UsersCollection"
//"pages/RestaurantPage/models/User"
],
function(routes, User) {
var _public = {};
var _private = {};
_private.init = function() {
// user = new User();
router = new routes();
};
_public.start = function() {
_private.init();
Backbone.history.start();
};
return _public;
}
);
LoginView.js
define([
"underscore",
"backbone",
"jquery",
"text!pages/RestaurantPage/templates/LoginTemplate.html"
],
function(_, Backbone, $, LoginTemplate) {
return Backbone.View.extend({
//model: LoginModel,
el: '#content',
render: function() {
var that = this;
var template = _.template($('#loginpage').html());
that.$el.html(template);
//router.navigate('admin', true);
}
});
}
);
routes.js
define([
"pages/RestaurantPage/views/LoginView",
"pages/RestaurantPage/views/AdminView",
"pages/RestaurantPage/views/CookerView",
"pages/RestaurantPage/views/WaiterView"
],
function(LoginView, AdminView, CookerView, WaiterView) {
return Backbone.Router.extend({
routes: {
"": "index",
"admin": "admin",
"cooker": "cooker",
"waiter": "waiter"
},
index: function() {
loginView = new LoginView;
loginView.render();
},
admin: function() {
adminView = new AdminView;
adminView.render();
},
cooker: function() {
cookerView = new CookerView;
cookerView.render();
},
waiter: function() {
waiterView = new WaiterView;
waiterView.render();
}
});
});
所有 View 都有相同的结构......那么问题是什么?
更新更改代码后如下:
define([
"underscore",
"backbone",
"jquery",
"text!pages/RestaurantPage/templates/LoginTemplate.html"
],
function(_, Backbone, $, Template) {
return Backbone.View.extend({
template: _.template(Template),
el: '#content',
render: function() {
this.$el.html(this.template());
return this;
//router.navigate('admin', true);
}
});
}
);
错误消失了...但没有任何渲染!这让我很生气:)
最佳答案
尝试像这样反转您的配置声明:
require.config({
paths: {
jquery: 'libs/jquery/jquery',
backbone: 'libs/backbonejs/backbone',
underscore: 'libs/underscorejs/underscore',
text: 'libs/requirejs/text',
templates: 'pages/RestaurantPage/templates',
views: 'pages/RestaurantPage/views',
collections: 'pages/RestaurantPage/collections',
models: 'pages/RestaurantPage/models',
routers: 'pages/RestaurantPage/routers',
application: 'application'
},
shim: {
underscore: {
exports: '_'
},
backbone: {
deps: [
'underscore',
'jquery'
],
exports: 'Backbone'
}
}
});
关于javascript - RequireJS 不起作用!(未捕获类型错误 : Cannot call method 'replace' of undefined),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23170379/
今天有小伙伴给我留言问到,try{...}catch(){...}是什么意思?它用来干什么? 简单的说 他们是用来捕获异常的 下面我们通过一个例子来详细讲解下
我正在努力提高网站的可访问性,但我不知道如何在页脚中标记社交媒体链接列表。这些链接指向我在 facecook、twitter 等上的帐户。我不想用 role="navigation" 标记这些链接,因
说现在是 6 点,我有一个 Timer 并在 10 点安排了一个 TimerTask。之后,System DateTime 被其他服务(例如 ntp)调整为 9 点钟。我仍然希望我的 TimerTas
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我就废话不多说了,大家还是直接看代码吧~ ? 1
Maven系列1 1.什么是Maven? Maven是一个项目管理工具,它包含了一个对象模型。一组标准集合,一个依赖管理系统。和用来运行定义在生命周期阶段中插件目标和逻辑。 核心功能 Mav
我是一名优秀的程序员,十分优秀!