2012-09-17 53 views
0

我使用cordova的角色創建了一個自定義插件。我已經將插件的關鍵字/值添加到cordova.plist,並在本機ios代碼中編寫了插件。但是我只能在訪問過一次頁面之後才能得到結果。我不知道哪裏出了問題。如果cordova js需要一些初始化?爲什麼我的自定義插件只能在cordova(phonegap)中訪問過一次後才能工作?

<!DOCTYPE html> 
<html> 
<head> 
<title>Overview</title> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 

<script src="js/jquery.min.js"></script> 
<script type="text/javascript" src="cordova-2.0.0.js"></script> 

<style type="text/css"> 

    *{ margin:0; 
     padding:0; 
    } 

    body { 
     margin-left:0px; 
     width:1024px; 
     background-image: url("content/main/defaultbg.jpg"); 
     background-size:1024px 768px; 
    } 

</style> 
</head> 
<body> 
    <div id="slr_left_title"> 
    html code .... 
    </div> 
<script> 

setTimeout(function(){ 

    window.getReportList = function(reportCategory, successCallback) { 
     cordova.exec(successCallback, function(err) { 
        callback('get the category list error!'); 
        }, "SLReportList", "getlist", [reportCategory]); 
    }; 

    window.getReportList("atestcategory", function(result) { 
       alert(result); 
    }); 
},0); 
</script> 
</body> 
</html> 

回答

2

很難知道到底發生了什麼錯誤不知道你的插件試圖做的,看到自己的代碼,但這裏是我最好的猜測。

科爾多瓦插件是按需延遲加載的。因此,除非您至少撥打exec()至少一次,否則您的插件將無法使用。如果你的插件是偶爾用信息調用Javascript的,而且每次都沒有Javascript請求,那麼你需要在程序開始時在exec()插件上調用initialize方法。

相關問題