0
我在調用fetch
函數時出現錯誤。調用Backbone集合的獲取函數時出現「未定義不是函數」錯誤
Undefined is not a function Error in Backbone js
var models = Backbone.Model.extend({
userId: function() {
return this.get('userId');
},
id: function() {
return this.get('id');
},
body: function() {
return this.get('body');
}
});
//Collections
var todolistStore = Backbone.Collection.extend({
url: function() {
return 'https://jsonplaceholder.typicode.com/posts'
},
model: models,
parse: function(response) {
return response;
}
});
todolistStore.fetch();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.cdnjs.com/ajax/libs/underscore.js/1.1.4/underscore-min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js" type="text/javascript"></script>
看起來你需要先實例:'VAR的MyStore =新todolistStore() ; myStore.fetch();' –
@ChrisG仍然不能正常工作 –
您正在使用舊版本的下劃線和主幹。當我使用當前版本時,錯誤消失。 –