-
Notifications
You must be signed in to change notification settings - Fork 11
1.x Collection
beez.Collection は、MVCにおける Modelリスト を担当します。
Backbone.js の Collection をベースに作られているので、基本的な機能については Backbone.Collection を参照してください。
beez.Collectionは、Backbone.Collectionの薄いラッパーです。Backbone.Collectionのすべての機能は、beez.Collectionで利用可能です。
beez.Collection は、beez.manager.model と連携可能ですが、下記のような制限があります。
-
beez.Collectionの生成は、beez.manager.model.createCollection()を使用します。 -
beez.Collectionが管理する配下の Model にbeez.Modelを使用することは可能ですが、他のManager管理のものと違いJSONPathを使ってアクセスすることは出来ません。 - Manager上の
beez.Collectionの配下に新たにオブジェクトを生成することは出来ません。
上記以外の機能はすべて beez.Model と beez.manager.model の関係のように利用することが出来ます。
新しく MyCollection を定義する際は、beez.Collection とそのコレクションが管理するモデル beez.Model 定義します。
var MyModel = beez.Model.extend(
'MyModel',
{
midx: 'mymodel',
defaults: {
title: '',
completed: false
},
urlRoot: 'http://0.0.0.0:1109/p'
}
);
var MyCollection = beez.Collection.extend(
'MyCollection',
{
midx:'mycollection',
model: MyModell,
}
);midx の値は、beez.manager.model の Model管理上の index として使用されます。
View と同様、 Collection のインスタンス生成は beez.manager.model を利用して行います。
beez.manager.model を通した Collection のインスタンス生成例
beez.manager.model.createCollection('/@', MyCollection);'/@' 部分は Manager が管理する JSONPath で MyCollection を追加したい親のPathを指定します。
createしたCollectionのpathは、prefix + '/' + Collection#midx となり、今回の場合、MyCollection は beez.manager.model で '/@/mycollection' というPathで管理されます。
下記のように、beez.Manager上のbeez.Collection の配下に新たにオブジェクトを生成することは出来ません。
beez.manager.model.createCollection('/@', MyCollection);
beez.manager.model.create('/@/mycollection', HogeModel); // NG
beez.manager.model.create('/@/mycollection', HogeCollection); // NGView と同様、 Collection のインスタンス取得は beez.manager.model を利用して行います。
Manager で管理されている Model を取得する例
var myModel = beez.manager.model.get('/@/mycollection');使用する場合に制限はあるものの、基本的には、beez.Model と利用方法は同じです。
詳しくは、Model Backbone.Collection を参照してください。