backbone.js에 문제가 있습니다. 내가 액세스 할 수없는 기존 API의 프론트 엔드를 만들고있다. 문제는 컬렉션에 새 모델을 추가하려고 할 때 내 백팩에서 모델을 만들려고 할 때마다 URL에 속성 이름을 추가한다는 것입니다.단일 모델에서 백본의 URL에 아이디를 추가하는 것을 어떻게 중지합니까?
예 :
- 기본 URL =/API/데이터베이스
- 내가 객체 { "이름"으로 GET/POST를 수행 할 때 나는 GET =/API/데이터베이스
- 을 수행 할 때 " test "} = /api/database/test가 결과입니다.
누구나 이러한 동작을 피하는 방법을 알고 계십니까?
인사말
내보기 컨 :
window.databaseView = Backbone.View.extend({
el: '#content',
template: new EJS({url: 'js/templates/databaseView.ejs'}),
initialize: function() {
var self = this;
this.collection.fetch({
success: function() {
console.log(self.collection);
var test = self.collection.get("_system");
console.log(test);
self.collection.get("_system").destroy();
self.collection.create({name: "test"});
}
});
},
render: function(){
$(this.el).html(this.template.render({}));
return this;
}
});
모델 :
window.Database = Backbone.Model.extend({
initialize: function() {
'use strict';
},
idAttribute: "name",
defaults: {
}
});
컬렉션 :
window.ArangoDatabase = Backbone.Collection.extend({
model: window.Database,
url: function() {
return '../../_api/database/';
},
parse: function(response) {
return _.map(response.result, function(v) {
return {name:v};
});
},
initialize: function() {
this.fetch();
},
getDatabases: function() {
this.fetch();
return this.models;
},
dropDatabase: function() {
},
createDatabse: function() {
}
});
'idAttribute : "name"'을 (를) 설정했습니다. id는 이름이고 url 함수는 없으며 백본은 기본 URL 함수를 사용합니다. –