简体   繁体   English

如何在phonegap javascript函数中返回结果?

[英]how to return result in phonegap javascript function?

Hi I'm trying to return the result from the phonegap plugin method. 嗨,我正在尝试从phonegap插件方法返回结果。

I'like to do the following code. 我想做下面的代码。

  function table(tableName)
  {
        var rowCount_i;
        return {
                 tableName : tableName,
                 rowCount : function(){
                 window.plugins.getRowCount(
                                   tableName,
                  function(r)
                  {
                         rowcount_i = r; 
                  }
                  function(e)
                  {
                          alert(e); 
                  }

        );
        return rowCount_i;

     }
 };

 }

When i'm tried to run the following code... 当我尝试运行以下代码时...

  var tbl = new table("psd-person");
  alert(tbl.rowCount);

And the result is Undefined.. 结果是未定义的。

Is there any way to return the result in rowCount Method or can you show this rowCount method with defferd concept? 有什么方法可以在rowCount方法中返回结果,还是可以使用defferd概念显示此rowCount方法?

Please help me out.. Thanks in advance 请帮帮我..在此先感谢

try it with callback: 尝试使用回调:

function table(tableName)
{
  return {
    tableName : tableName,
    rowCount : function(callback){
      window.plugins.getRowCount(tableName,
        function(r)
        {
               rowcount_i = r; 
               callback(rowcount_i);
        }
        function(e)
        {
                alert(e); 
        });    
    }
  }
}

var tbl = new table("psd-person");
tbl.rowCount(function(rowcount_i) {
  alert(rowcount_i);
});

Not tested! 未经测试!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM