2013-07-20 44 views
0

这段代码在firefox和chrome中工作正常,但是当我尝试让它在android studio 2.0模拟器中工作时,它只显示{{questionTable [count ] .question}}不是绑定的数据。我可以做一个计数按钮,并在模拟器中增加罚款,但是当我尝试获得一个变量来通过数组增加,它将只能在浏览器中完美工作。当有人点击增量按钮时,循环这些问题的最佳方法是什么?angularjs遍历数组在浏览器中工作,但不在android模拟器webview

<!doctype html> 
    <html ng-app> 
    <head> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js">  </script> 
<script> 


    function myQuestions($scope) { 
    $scope.count = 0; 


    $scope.increaseCount = function(){ 
     $scope.count++; 

    } 

    $scope.questionTable = [ 

     {    question:'A child swallows bleach', 
      answer1:'call poison control hotline', 
      answer2:'call police', 
      answer3:'induce vomiting', 
      answer4:'suction stomach', 
      correct:'answer1', 
      rational:'always call poison control' 

     }, 
     { 
      question: 'A 16 yr old is admitted for acute appendicites and has his appendix removed. What is important for normal development and growth?', 
      answer1: 'Encourage child to rest and read', 
      answer2: 'Let the parents room in with the child', 
      answer3: 'Allow family to bring computer games', 
      answer4: 'Allow the child to participate in activiites with other children the same age', 
      correct: 'answer4', 
      rational: 'Adolescents are not sure the want their parents with them when hospitalized. Seperation from friends is a source of anxiety. Ideally the peer group will support the ill friend.' 
     } 
    ]; 

     } 

     </script> 

    </head> 
    <body> 

    <div ng-controller = "myQuestions"> 
     {{questionTable[count].question}} 
    <button ng-click="increaseCount()" >count</button> 
    </div> 
    </body> 
    </html> 

和java文件看起来像这样。我粘贴上述HTML文件到customHtml串下面

public class MainActivity extends Activity { 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    WebView wv = (WebView)findViewById(R.id.my_webview); 
    wv.setWebViewClient(new WebViewClient() { 
     @Override 
     public boolean shouldOverrideUrlLoading(WebView view, String url) { 
      view.loadUrl(url); 
      return true; 
     } 
    }); 

    wv.getSettings().setJavaScriptEnabled(true); 
    String customHtml = "<!doctype html..."; 
    wv.loadData(customHtml, "text/html", "UTF-8"); 

} 

}

回答

2

当包括代码直在String很容易弄乱转义。我怀疑这是你的错误所在。我将您的代码复制到一个资产文件(questions.html)中,并使用loadUrl()加载,它的行为如预期。

wv.loadUrl("file:///android_asset/questions.html"); 
+0

谢谢。这对我有效。 – cubeloid

相关问题