2016-09-14 113 views
0

在那休息api網址,我得到一個json數組並獲取與EmployeeList集合。使用fetch()只調用其餘的api。如果我沒有使用抓取,其餘API調用不起作用,它使用api代碼中的日誌進行測試。雖然取得我得到的所有細節,但我得到的錯誤,fetch收集使用其餘api骨幹

Uncaught TypeError: this.model is not a constructor backbone-min.js:24 

我是新的backbonejs。什麼是錯誤,爲什麼會發生這個錯誤。我的代碼如下,

var app = {}; 
app.Employee = Backbone.Model.extend(); 
app.employee = new app.Employee(); 
app.EmployeeList = Backbone.Collection.extend({ 
    model: app.employee, 
    url:'/api/employ', 
    parse: function(response) { 
     return response; 
    } 
}) 
app.employeeList = new app.EmployeeList(); 
app.employeeList.fetch(); 
app.AppView = Backbone.View.extend({ 
    el: '#emp', 
    initialize: function(){ 
     this.render(); 
     console.log(app.employeeList); 
    }, 
    render: function(){ 
     this.$el.html('sathish'); 
    } 
}); 
app.appView = new app.AppView(); 

回答

1

變化

app.EmployeeList = Backbone.Collection.extend({ 
    model: app.employee, 
    ..... 
}) 

app.EmployeeList = Backbone.Collection.extend({ 
    model: app.Employee, 
    ... 
}) 

模型PARAM應該是一個模型類(在JS一個構造函數)一樣app.Employee。

+0

感謝它的工作。 – Sathish

0

您應該提供app.Employee()而不是new app.Employee()作爲集合的模型參數。

+0

當使用像那樣的錯誤是左側分配錯誤時, – Sathish