0

このフィドルは、私がやろうとしていることを多かれ少なかれ示しています。

Parse.com データベースからいくつかの結果を照会しています。結果は、成功のコールバックで返されます。

mainView()関数でそれらを操作するための最良の方法を誰か教えてもらえますか? すべてのクエリを、それらがどのように表示されるかのロジックから分離したいと思います。私はかなりの数の異なるアプローチを試みましたが、それを機能させることができませんでした。

4

1 に答える 1

2

thisコールバックの外部への参照を格納するだけです。

    var userInterface = {


    newQuery: function() {
        var that=this; //store a reference to "this"

        Query = Parse.Object.extend("Test"); 
        query = new Parse.Query(Query);

        query.descending("createdAt");    
        query.equalTo("column1", "a");

        query.find({
            success:function(results){

                 that.mainView(results); //that points to the userInterface object

            },
            error:function(error){

            }


        });
    }, 



    mainView: function(res){

        console.log(res);

    },

    init: function() {
       this.newQuery();        
    }

};
userInterface.init(); 

http://jsfiddle.net/4XsLq/8/

于 2013-02-21T03:27:05.323 に答える