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 回答