방금 Backbone.js로 시작했으며 중첩 모델 및 컬렉션에 문제가 있습니다.중첩 모델 및 컬렉션 (하위 컬렉션)을 만드는 방법
이 예에서는 단일 종단 점 /vocabulary.json
만 있습니다. 여기
[
{
"id": 1,
"words": [
{
"native": "hello",
"foreign": "hola"
},
{
"native": "yes",
"foreign": "si"
},
{
//... More words in this lesson
}
]
},
{
//... More lessons coming from this endpoint
}
]
그것은 기본적으로 lessons
의 모음으로, 그리고 각 lesson
어휘 words
의 컬렉션이 있습니다.
다른 url
끝 점이없는 words
컬렉션을 만들려면 어떻게해야합니까 (컬렉션에 필요합니까?)?
여기까지 제가 지금까지 가지고 있습니다. 사실, 이것은 내가 노력하고있는 모든 것이 작동하지 않기 때문에 제거 된 기본 버전입니다.
내가이 완전히 잘못에 대해 생각하고, 아마
Entities.Vocabulary = Backbone.Model.extend({});
Entities.Vocabularies = Backbone.Collection.extend({
model: Entities.Vocabulary,
url: "/vocabulary.json"
});
// Here is where I am struggling
Entities.Vocabulary.Word = Backbone.Model.extend({
// what to do?
});
Entities.Vocabulary.Words = Backbone.Collection.extend({
// what to do?
// Need some method to go into the Entities.Vocabularies Collection, pluck a given id
// and return the "words" attribute as a new Collection to work from.
});
을 /entities/vocabulary.js,하지만 난 당신이 나를 도와 도와 내 문제가 충분히 설명했다 희망하고있다.