0

这段代码在 firefox 和 chrome 中运行良好,但是当我尝试让它在 android studio 2.0 模拟器中运行时,它只显示 {{questionTable[count].question}} 而不是绑定数据。我可以制作一个计数按钮并在模拟器中很好地递增它,但是当我尝试让一个变量通过数组递增时,它只会在浏览器中完美运行。当有人点击增量按钮时,循环这些问题的最佳方法是什么。

    <!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");

}

}

4

1 回答 1

2

当直接在 a 中包含代码时String,很容易混淆转义。我怀疑这就是你的错误所在。我将您的代码复制到一个资产文件 (questions.html) 中并用 加载loadUrl(),它的行为符合预期。

wv.loadUrl("file:///android_asset/questions.html");
于 2013-07-20T20:37:43.257 回答