1
我正在開發一個帶有jQuery Mobile和PhoneGap的Android應用程序。這是我的活動:jquery mobile和phonegap addJavascriptInterface
public class xxx extends DroidGap {
/** Called when the activity is first created. */
private String FILENAME = "";
private static final String HTML_ROOT = "file:///android_asset/www/";
private Handler handler = null;
private static WebView webView = null;
public MyTeam team = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.init();
handler = new Handler();
FILENAME = getString(R.string.fileName);
//parsing data from file
String json = readFile();
team = parseJson(json);
appView.addJavascriptInterface(this, "MyTeam");
super.loadUrl("file:///android_asset/www/menu.html");
}
public String HW(){
return team.getTeamName();
}
這是menu.html我的Javascript代碼:
$(document).ready(function(){
alert(MyTeam.HW()); // work perfectly
alert("name "+MyTeam.team.getTeamName()); //doesn't work!
});
所以問題是:
- 我可以訪問硬件的函數,返回我team.getTeamName();
- 我沒有權限訪問我的活動中的團隊變量名稱,因爲MyTeam.team.getTeamName()不起作用。
看來我只能訪問函數,而不能直接訪問公共變量。
我做錯了什麼?
謝謝。