下面的代码在 Chrome 的 JavaScript 控制台中给了我这个错误:
未捕获的类型错误:未定义不是函数
堆栈跟踪:
(anonymous function) ember-1.0.0-rc.3.js:22443
b.extend.each jquery-1.9.1.min.js:3
b.fn.b.each jquery-1.9.1.min.js:3
Ember.Handlebars.bootstrap ember-1.0.0-rc.3.js:22432
bootstrap ember-1.0.0-rc.3.js:22454
(anonymous function) ember-1.0.0-rc.3.js:12646
Ember.runLoadHooks ember-1.0.0-rc.3.js:12645
Ember.Application.Ember.Namespace.extend._initialize ember-1.0.0-rc.3.js:26808
(anonymous function) ember-1.0.0-rc.3.js:4504
Ember.handleErrors ember-1.0.0-rc.3.js:411
invoke ember-1.0.0-rc.3.js:4502
iter ember-1.0.0-rc.3.js:4572
RunLoop.flush ember-1.0.0-rc.3.js:4626
RunLoop.end ember-1.0.0-rc.3.js:4531
tryable ember-1.0.0-rc.3.js:4732
Ember.tryFinally ember-1.0.0-rc.3.js:1199
Ember.run.end ember-1.0.0-rc.3.js:4735
autorun
使用 Ember 的 dev 版本,在引导过程中会出现这个错误:
Ember.Handlebars.bootstrap = function(ctx) {
var selectors = 'script[type="text/x-handlebars"], script[type="text/x-raw-handlebars"]';
Ember.$(selectors, ctx)
.each(function() {
// Get a reference to the script tag
var script = Ember.$(this);
var compile = (script.attr('type') === 'text/x-raw-handlebars') ?
Ember.$.proxy(Handlebars.compile, Handlebars) :
Ember.$.proxy(Ember.Handlebars.compile, Ember.Handlebars),
// Get the name of the script, used by Ember.View's templateName property.
// First look for data-template-name attribute, then fall back to its
// id if no name is found.
templateName = script.attr('data-template-name') || script.attr('id') || 'application',
/**** ERROR HERE ****/
template = compile(script.html());
我的 HTML 代码(JS 是取自 Ember 主页的示例代码):
<!doctype html>
<html>
<head>
<title></title>
</head>
<body>
<div id="mapTemplate">
<canvas style="border: thick solid black" id="mapDesigner" width="500" height="500"></canvas>
</div>
<script src="3rdParty/jQuery/jquery-1.9.1.min.js"></script>
<script src="3rdParty/HandlebarsJS/handlebars.runtime.js"></script>
<script src="3rdParty/EmberJS/ember-1.0.0-rc.3.min.js"></script>
<script type="text/x-handlebars">
{{outlet}}
</script>
<script type="text/x-handlebars" id="index">
<h1>People</h1>
<ul>
{{#each model}}
<li>Hello, <b>{{fullName}}</b>!</li>
{{/each}}
</ul>
</script>
<script>
$(function () {
App = Ember.Application.create();
App.Person = Ember.Object.extend({
firstName: null,
lastName: null,
fullName: function() {
return this.get('firstName') +
" " + this.get('lastName');
}.property('firstName', 'lastName')
});
App.IndexRoute = Ember.Route.extend({
model: function() {
var people = [
App.Person.create({
firstName: "Tom",
lastName: "Dale"
}),
App.Person.create({
firstName: "Yehuda",
lastName: "Katz"
})
];
return people;
}
});
});
</script>
</body>
</html>
库版本:
Handlebars.js:1.0.0-rc.3
Ember.js:1.0.0-rc.3
jQuery:1.9.1
jsFiddle 游乐场