Javascript 无法获取主干。木偶应用正在运行
我是主干网的新手。我和木偶正在使用相同的工具开发一个电话簿应用程序。我提到过 我遇到以下错误:Javascript 无法获取主干。木偶应用正在运行,javascript,marionette,Javascript,Marionette,我是主干网的新手。我和木偶正在使用相同的工具开发一个电话簿应用程序。我提到过 我遇到以下错误: TypeError: Backbone.Model.Extend is not a function index.html (line 109) listAll: function(){ 到目前为止,我的代码是: var MyApp = new Backbone.Marionette.Application(); MyApp.a
TypeError: Backbone.Model.Extend is not a function index.html (line 109)
listAll: function(){
到目前为止,我的代码是:
var MyApp = new Backbone.Marionette.Application();
MyApp.addRegions({
mainRegion: "#container"
});
PhoneDirectory = Backbone.Model.Extend({
search: function(event){
event.preventDefault();
$("#results").html("");
$.get("lookup_single_phone_number.jsp", { name: $("#name").val() })
.done(function(data){
$("#results").html(data);
})
.error(function(error){
$("#results").html(error.status + " " + error.statusText);
});
},
listAll: function(){ // line # 109
$.get("lookup_all_phone_numbers.jsp")
.done(function(data){
var data = JSON.parse(data);
$("#results").html("");
var table=$('<table>');
table.append('<tr><th>Name</th><th>Phone Number</th></tr>');
$.each(data, function(index, value){
table.append("<tr><td>" + value + "</td><td>" + index + "</td></tr>");
});
$("#results").append(table);
})
.error(function(error){
$("#results").html(error.status + " " + error.statusText);
});
}
});
PhoneDirectories = Backbone.Collection.Extend({
model: PhoneDirectory,
search: function(event){
event.preventDefault();
$("#results").html("");
$.get("lookup_single_phone_number.jsp", { name: $("#name").val() })
.done(function(data){
$("#results").html(data);
})
.error(function(error){
$("#results").html(error.status + " " + error.statusText);
});
},
listAll: function(){
$.get("lookup_all_phone_numbers.jsp")
.done(function(data){
var data = JSON.parse(data);
$("#results").html("");
var table=$('<table>');
table.append('<tr><th>Name</th><th>Phone Number</th></tr>');
$.each(data, function(index, value){
table.append("<tr><td>" + value + "</td><td>" + index + "</td></tr>");
});
$("#results").append(table);
})
.error(function(error){
$("#results").html(error.status + " " + error.statusText);
});
}
});
SinglePhoneNumberView = Backbone.Marionette.ItemView.extend({
template: "#results_template",
tagName: 'tr',
events: {
'submit #lookup': 'search',
'click #list_all': 'listAll'
},
search: function(event){
event.preventDefault();
$("#results").html("");
$.get("lookup_single_phone_number.jsp", { name: $("#name").val() })
.done(function(data){
$("#results").html(data);
})
.error(function(error){
$("#results").html(error.status + " " + error.statusText);
});
},
listAll: function(){
$.get("lookup_all_phone_numbers.jsp")
.done(function(data){
var data = JSON.parse(data);
$("#results").html("");
var table=$('<table>');
table.append('<tr><th>Name</th><th>Phone Number</th></tr>');
$.each(data, function(index, value){
table.append("<tr><td>" + value + "</td><td>" + index + "</td></tr>");
});
$("#results").append(table);
})
.error(function(error){
$("#results").html(error.status + " " + error.statusText);
});
}
});
AllPhoneNumberView = Backbone.Marionette.CompositeView.extend({
template: "#results_template",
tagName: 'tr',
itemView: SinglePhoneNumberView
});
如何获取按钮以在控制台中获取消息?是否在backbone.js之前包含下划线.js?是的。应该是另一种方式吗?我的顺序是:jQuery、下划线、主干、主干.localstorage、主干.marinotte.
.Extend
-->.Extend
。谢谢@WillM,现在我没有收到任何错误。但单击按钮时没有输出:(
var MyApp = new Backbone.Marionette.Application();
MyApp.addRegions({
mainRegion: "#container"
});
PhoneDirectory = Backbone.Model.Extend({
listAll: function(){ // line # 109
$.get("lookup_all_phone_numbers.jsp")
.done(function(data){
var data = JSON.parse(data);
$("#results").html("");
var table=$('<table>');
table.append('<tr><th>Name</th><th>Phone Number</th></tr>');
$.each(data, function(index, value){
table.append("<tr><td>" + value + "</td><td>" + index + "</td></tr>");
});
$("#results").append(table);
})
.error(function(error){
$("#results").html(error.status + " " + error.statusText);
});
}
});
PhoneDirectories = Backbone.Collection.Extend({
model: PhoneDirectory,
listAll: function(){
$.get("lookup_all_phone_numbers.jsp")
.done(function(data){
var data = JSON.parse(data);
$("#results").html("");
var table=$('<table>');
table.append('<tr><th>Name</th><th>Phone Number</th></tr>');
$.each(data, function(index, value){
table.append("<tr><td>" + value + "</td><td>" + index + "</td></tr>");
});
$("#results").append(table);
})
.error(function(error){
$("#results").html(error.status + " " + error.statusText);
});
}
});
SinglePhoneNumberView = Backbone.Marionette.ItemView.extend({
template: "#results_template",
tagName: 'tr',
events: {
'click #list_all': 'listAll'
},
listAll: function(){
$.get("lookup_all_phone_numbers.jsp")
.done(function(data){
var data = JSON.parse(data);
$("#results").html("");
var table=$('<table>');
table.append('<tr><th>Name</th><th>Phone Number</th></tr>');
$.each(data, function(index, value){
table.append("<tr><td>" + value + "</td><td>" + index + "</td></tr>");
});
$("#results").append(table);
})
.error(function(error){
$("#results").html(error.status + " " + error.statusText);
});
}
});
AllPhoneNumberView = Backbone.Marionette.CompositeView.extend({
template: "#results_template",
tagName: 'tr',
itemView: SinglePhoneNumberView
});
MyApp.start();