Ver código fonte

object array operation done

night-cherry 1 mês atrás
pai
commit
a9e8c2fcff
2 arquivos alterados com 8 adições e 7 exclusões
  1. 1 1
      index.html
  2. 7 6
      index.js

+ 1 - 1
index.html

@@ -49,7 +49,7 @@
 		<hr/>
 		<button @click="interface_web()">connect to tomcat</button>
 		<br/>
-		<h4>tomcat_res -></h4><h4> {{ tomcat_res==""?"content empty":tomcat_res }}</h4>
+		<h4>tomcat_res -> {{ tomcat_res==""?"content empty":tomcat_res }}</h4>
 		<hr/>
 		<h2>书籍列表</h2>
 		<table>

+ 7 - 6
index.js

@@ -63,7 +63,7 @@ const app=createApp({
         {value: 'en', label: 'English',},
         {value: 'ja', label: 'にほんご',},
       ],
-      tomcat_res:"",
+      tomcat_res:"tomcat",
       books:[
         {title:"Linux从入门到精通",author:"night-cherry",publisher:"peking press",pages:123},
         {title:"MySQL必知必会",author:"李晓兵",publisher:"peking press",pages:456},
@@ -88,13 +88,14 @@ const app=createApp({
       console.log("this.tomcat_res : "+this.tomcat_res);
       console.log("------this.books : "+this.books);
       const _books=this.books;
+      const _tomcat_res=this.tomcat_res;
       // console.log("------this : "+this);
       const request = new XMLHttpRequest();
       request.onload=function(){
         console.log("--------parse tomcat server string--------");
         const res=JSON.parse(request.responseText);
 
-        this.tomcat_res=res[0].title;
+        _tomcat_res=res[1].title;
         console.log("res:"+res);
         console.log("res[0].title :"+res[0].title);
         console.log("res[0].author :"+res[0].author);
@@ -106,16 +107,16 @@ const app=createApp({
         console.log("res[1].publisher :"+res[1].publisher);
         console.log("res[1].pages :"+res[1].pages);
         console.log("this.tomcat_res : "+this.tomcat_res);
-        alert("this.tomcat_res : "+this.tomcat_res);
+        alert("this.tomcat_res : "+_tomcat_res);
         
         console.log("------  _books : "+_books);
         // console.log("------this.books : "+this.books);
         try{
-          _books.push(res[0]);
+          _books.concat(res);
         }catch(e){
           console.log("the way == _books.push(res[0])  is wrong!!!");
           try{
-            _books.concat(res);
+            _books.push(res[0]);
 
           }catch(e){
             console.log("the way == _books.push(res[0])  is wrong!!!");
@@ -127,7 +128,7 @@ const app=createApp({
       
         // console.log("------books : "+books);
         // console.log("------this : "+this);
-        console.log("this.tomcat_res : "+this.tomcat_res);
+        console.log("this.tomcat_res : "+_tomcat_res);
       };
       request.open("POST","http://ancientapes.cc:8080/mineluxuries/book");
       request.send("test tomcat");