不能设置property 'new_form'的定义
Cannot set property 'new_form' of undefined
我遇到了来自Treehouse的Backbone.js教程的麻烦。下面是我的代码:
var NotesApp = (function () {
var App = {
stores: {}
}
App.stores.notes = new Store('notes');
// Note Model
var Note = Backbone.Model.extend({
//Local Storage
localStorage: App.stores.notes,
initialize: function () {
if (!this.get('title')) {
this.set({
title: "Note at " + Date()
})
};
if (!this.get('body')) {
this.set({
body: "No Body"
})
};
}
})
//Views
var NewFormView = Backbone.View.extend({
events: {
"submit form": "createNote"
},
createNote: function (e) {
var attrs = this.getAttributes(),
note = new Note();
note.set(attrs);
note.save();
},
getAttributes: function () {
return {
title: this.$('form [name=title]').val(),
body: this.$('form [name=body]').val()
}
}
});
window.Note = Note;
$(document).ready(function () {
App.views.new_form = new NewFormView({
el: $('#new')
});
})
return App
})();
我得到错误:Cannot set property 'new_form' of undefined
我试着回去尽可能地复制代码,但我仍然不能让它工作。有什么建议吗?
stores: {}
后添加,
views: {}
你需要一个对象来附加你的视图- JavaScript没有可视
相关文章:
- 用嵌套函数和默认函数定义函数
- Dojo不解析自定义小部件的模板html中的小部件声明性
- 为什么“;未定义的“;在JavaScript中结束循环
- Angular Schema Form-自定义对象编辑器
- 如何使用组件和自定义验证实现Angular 1 Form
- $scope.form.$error在Angular控制器中未定义
- 无法在茉莉花测试中调用$scope.form.$submitted:未定义
- jQuery 验证 未捕获的类型错误 无法读取未定义的属性“form”
- Node.js, express, html form req.body 是未定义的
- IE8称原型's Form类未定义
- TypeError:c在使用DataTable中的new entry Form保存新条目时未定义
- 是否可以使用一些自定义选项调用$('form').validationEngine('valid
- javascript中未定义错误document.form
- JavaScript - 'this.form'返回未定义
- jQuery验证:$.data($('form')[0],'验证器').设置返回未定义
- 使用jQuery Validate插件时,form action/URL应该在哪里定义
- AngularJS - form inside ng-repeat在控制器中未定义
- 项目列表中的Spring Form Taglib和自定义属性
- 是否可以添加自定义元素作为'form元素'在angularJs中使用ng-dirty和ng-质朴
- 文档.[form element]未定义