LoginSignup
1
0

More than 5 years have passed since last update.

NCMBとMONACAを使ってアプリ開発(roleとfetchUserをまとめる)

Posted at

fetchUserの使い方

roleにいるユーザー一覧を取得するためのfetchUser。これは使い方的には簡単。なぜなら解説があるから。

NCMBのサンプルのページ(会員のグルーピング)

ちょっと使い方が整理しないとわからなかったから整理がてら。

ほぼサンプルと同じサンプル

function getUserBelongGroup(roleName){
    ncmb.Role.fetchAll()
             .then(function(results){
                return results[0].fetchUser(); ←ここでroleに所属しているユーザーがとれる
             })
             .then(function(users){
                alert(users.length); ←すぐに使うとobject Promiseになるけど、一回thenを挟むと大丈夫。なぜ?
                alert(users[0].userName);
                alert(users[1].userName);
             })
             .catch(function(err){
                 alert(err);
             })   
}

自分が所属しているroleを取得する(グループ一覧)の方法考察

自分が所属しているrole一覧を取得するには、全部のroleをfetchUserして、その中に自分がいたらRoleの名称をどっかにつっこむ、的なのがいるのか?それとも、自分がroleに入った時に、USERコレクションのaclに追加しておくべきか。多分後者が楽な気がするがどうだろう。。。速度的には後者な気がする。もしくはUserコレクションにroleフィールドを持たせて配列で中に突っ込んどくとか?

次回は自分が所属しているrole一覧を表示、をやります。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0