2017-05-17 19 views
0

我怎麼只能說明這部分如何顯示JSON數組的一部分?

/DB/User_DataDb/61500546-4e63-42fd-9d54-b92d0f7b9be1這整個

對象obj.sel_an的

[ 
    { 
     "__zone_symbol__state":true, 
     "__zone_symbol__value":"/db/User_DataDb/61500546-4e63-42fd-9d54-b92d0f7b9be1" 
    } 
] 

我寫了

console.log("obj.sel_an: ", 
JSON.stringify(this.sel_and.__zone_symbol__value)) 

而控制檯顯示t他的錯誤:'obj.sel_an:undefined。'

enter image description here

+0

'this.sel_and [0]。 __zone_symbol__value' – dbandstra

+0

@dbandstra \t 你好,謝謝,它的工作。如果我知道對象的確切索引,它就會工作。 如果對象具有更多信息並位於數據庫集合中,我想要複製該信息並將其保存在另一個數據庫集合中。然後我想用Angular2同時顯示兩個集合的保存數據。 你也許知道我該怎麼做? 我試圖將這個對象保存到數據庫中作爲Set()和Array()並在html中顯示它。 但它不工作。或者我應該試着問一下論壇? – ran

+0

使用'this.sel_and'對象上的'for'循環或forEach函數。例如:'this.sel_and.forEach(function(child){console.log(child .__ zone_symbol__value)});' – Misaz

回答

0

@Misaz here is my answer I talked about in the last comment.

Here is a section or rather a part of my code

db.Coll1.find() 
     .equal('id', and.id) 
.resultList(result => { 
       result.forEach(db1 => { 
        if (db1.sel_and === null) { 
        db1.sel_and = new Set();                 
       } 

       if (db1.sel_an === null) { 
        db1.sel_an = new Array(); 
       } 


db1.sel_an.push(promise1); // here is a JsonArray 
db1.sel_and.add(promise1); // here is a Set() 



    var db_child: any; 
    db_child = db1.sel_and.forEach(function (child) {console.log(child[0].__zone_symbol__value) }); 
    console.log(" db1.sel_and: ", db_child); 
    return db1.update({ refresh: true }); 
    }); 

Here is the result by JsonArray

  1. By db1.sel_an.push(promise1);
    save in collection

    [ { "__zone_symbol__state": true, "__zone_symbol__value": "/db/User_DataDb/f6fe3fe3-17f1-49d8-83c3-b36dda42026d" } ]

Console output:

ZoneAwarePromise {__zone_symbol__state: null, __zone_symbol__value: Array(0)} 
    __zone_symbol__state:true 
    __zone_symbol__value:"/db/User_DataDb/d79ef084-17fc-441c-a8eb-13ba0a14f083" 
    __proto__:Object 
  • 這裏是集()
  • 的結果 - >「db1.sel_and.add(承諾1);「 - >保存爲[null]收藏N,但它應該被保存爲 - >[ 「/分貝/ User_DataDb/f55bf96d-2cb9-467f-8aa8-d60aced32fcf」]

    Set(1) {ZoneAwarePromise {__zone_symbol__state: true, __zone_symbol__value: "/db/User_DataDb/f55bf96d-2cb9-467f-8aa8-d60aced32fcf"}} 
        size:(...) 
        __persistedSize__:1 
        __persistedState__:Object 
        __proto__:Set 
        [[Entries]]:Array(1) 
        0:null 
        length:1 
    
    3.  
    
    db_child = db1.sel_and.forEach(function (child) { console.log(child[0].__zone_symbol__value) }); 
        console.log(" db1.sel_and: ", db_child); 
    

    I tried it with child[0].__zone_symbol__value But I got errors:

    Uncaught (in promise): TypeError: Cannot read property '__zone_symbol__value' of undefined 
    TypeError: Cannot read property '__zone_symbol__value' of undefined 
        at http://localhost:3000/main.bundle.js:28348:116 
        at Set.forEach (native) 
        at http://localhost:3000/main.bundle.js:28348:69 
        at Array.forEach (native) 
        at http://localhost:3000/main.bundle.js:28336:44 
        at ZoneDelegate.invoke (http://localhost:3000/polyfills.dll.js:4341:26) 
        at Object.onInvoke (http://localhost:3000/vendor.dll.js:30326:37) 
        at ZoneDelegate.invoke (http://localhost:3000/polyfills.dll.js:4340:32) 
        at Zone.run (http://localhost:3000/polyfills.dll.js:4133:43) 
        at http://localhost:3000/polyfills.dll.js:4720:57 
        at ZoneDelegate.invokeTask (http://localhost:3000/polyfills.dll.js:4374:31) 
        at Object.onInvokeTask (http://localhost:3000/vendor.dll.js:30317:37) 
        at ZoneDelegate.invokeTask (http://localhost:3000/polyfills.dll.js:4373:36) 
        at Zone.runTask (http://localhost:3000/polyfills.dll.js:4173:47) 
        at drainMicroTaskQueue (http://localhost:3000/polyfills.dll.js:4553:35) 
        at ZoneTask.invoke (http://localhost:3000/polyfills.dll.js:4431:25) 
    

    If I don’t write [0] at the end of child, I get 「undefined」.If I written child.__zone_symbol__value, I get wrong . How can I leave out the 「[0].__zone_symbol__value」 without getting an error? Is it possible at all?

    由於