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

コードを aStringに直接含めると、エスケープを台無しにするのは簡単です。それがあなたのエラーの場所だと思います。コードをアセット ファイル (questions.html) にコピーして でロードしたloadUrl()ところ、期待どおりに動作しました。

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