Help us understand the problem. What is going on with this article?

monacaからNCMBのデータを取得する

More than 3 years have passed since last update.

ここで述べるやり方はSDKバージョン1.2.6の旧バージョンに対応しています。

作業手順としては
1 データのクエリを作成する
2 求める条件を指定
3 クエリに対してfindメソッドを実行
4 得られたオブジェクトにgetメソッドを用いてデータを取得

var ScoreClass = NCMB.Object.extend("Score");//Scoreはデータのクラス名
var scoreQuery = new NCMB.Query(ScoreClass);//クエリを作成する

//欲しいデータの条件をしていする(この場合はobjectIdがxxxxであるデータのオブジェクト)
scoreQuery.equalTo("objectId","xxxx");

scoreQuery.find({ //クエリにfindメソッドを使う
    success: function(results){
        var ans = results[0];//データのオブジェクトが得られる
        console.log(ans.get("score"));//取得したオブジェクトにgetメソッドを使い取得したいフィールド名を指定する
    },
    error: function(error){
        console.log("error : " + error.message);
    }
});

データストアのobjectId自体の取得について
objectIdは

scoreQuery.find({
    success: function(results){
        for(var i = 0; i < results.length; i++){
            console.log(results[i].id);//objectIdを取得できる
        }
    },
    error: function(error){
        console.log(error.message);
    }
});

とすることで可能である

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away