为什么返回的数据相同?

时间:2017-08-25 06:36:40

标签: javascript json node.js



let statList = {
  title: {
    x: "center"
  },
  xAxis: {
    type: "category",
    axisTick: {
      alignWithLabel: true
    }
  },
  yAxis: {
    type: "value"
  }
};

let statObj = {};

statObj.chatObj = Object.create(statList);
statObj.carObj = Object.create(statList);
statObj.saObj = Object.create(statList);

statObj.chatObj.xAxis.data = [1, 2, 3];
statObj.carObj.xAxis.data = [4, 5, 6];
statObj.saObj.xAxis.data = [7, 8, 9];

console.log(statObj)




为什么返回的statObj.XX.xAxis.data相同?

为什么当我使用console.log(JSON.stringify(statObj))时,结果为{"chatObj":{},"carObj":{},"saObj":{}}

2 个答案:

答案 0 :(得分:2)

设置statObj.chatObj.xAxis时,xAxis上找不到chatObj,因此在原型链上搜索xAxis statList是{chatObj的原型1}}),我们可以在那里找到它。到目前为止,我们已完成部分statObj.chatObj.xAxis,接下来我们将创建一个.data密钥,该密钥将在statList.xAxis上创建。 statObj.carObj.xAxis.data statObj.saObj.xAxis.data statObj.chatObj.xAxis.data statList.xAxis.data statObj.XX.xAxis.data [7, 8, 9] [INFO] | 08-04-2017 14:47:56 | | o.apache.solr.core.SolrCore.Request.preDecorateResponse | 5600fce7-f6f8-4827-831b-1b9480f62355 | {update.distrib = TOLEADER & distrib.from = http: // devm50: 8091 / Solr / INDEXING_TEST_shard2_replica1 / & wt = javabin & version = 2 & queryId = 5600fce7-f6f8-4827-831b-1b9480f62355} [INFO] | 08-04-2017 14:47:56 | | o.a.s.u.p.LogUpdateProcessorFactory.finish | 5600fce7-f6f8-4827-831b-1b9480f62355 | [INDEXING_TEST_shard3_replica2] webapp = / Camino de Solr = / update queryId = 5600fce7-f6f8-4827-831b-1b9480f62355 params = {update.distrib = TOLEADER & distrib.from = http: // devm50: 8091 / Solr / INDEXING_TEST_shard2_replica1 / & wt = javabin & version = 2 } {add = [6040]} 0 3 [INFO] | 08-04-2017 14:47:56 | | o.apache.solr.core.SolrCore.Request.preDecorateResponse | 6d8646b5-f909-4b9c-9cba-313081ef0ba6 | {update.distrib = TOLEADER & distrib.from = http: // devm50: 8091 / Solr / INDEXING_TEST_shard2_replica1 / & wt = javabin & version = 2 & queryId = 6d8646b5-f909-4b9c-9cba-313081ef0ba6} [INFO] | 08-04-2017 14:47:56 | | o.a.s.u.p.LogUpdateProcessorFactory.finish | 6d8646b5-f909-4b9c-9cba-313081ef0ba6 | [INDEXING_TEST_shard3_replica2] webapp = / Solr path = / update queryId = 6d8646b5-f909-4b9c-9cba-313081ef0ba6 params = {update.distrib = TOLEADER & distrib.from = http: // devm50: 8091 / Solr / INDEXING_TEST_shard2_replica1 / & wt = javabin & version = 2 } {add = [6041]} 0 6 [INFO] | 08-04-2017 14:47:56 | | o.apache.solr.core.SolrCore.Request.preDecorateResponse | bc1911d6-e785-4b23-9730-127b3a751df5 | {update.distrib = TOLEADER & distrib.from = http: // devm50: 8091 / Solr / INDEXING_TEST_shard2_replica1 / & wt = javabin & version = 2 & queryId = bc1911d6-e785-4b23-9730-127b3a751df5} [ERROR] | 08-04-2017 14:47:56 | | o.a.solr.update.StreamingSolrClients.handleError | | error java.net.ConnectException: Connection refused: connect en java.net.DualStackPlainSocketImpl.waitForConnect (Método nativo) en java.net.DualStackPlainSocketImpl.socketConnect (DualStackPlainSocketImpl.java:85) en java.net.AbstractPlainSocketImpl.doConnect (AbstractPlainSocketImpl.java:350) en java.net.AbstractPlainSocketImpl.connectToAddress (AbstractPlainSocketImpl.java:206) en java.net.AbstractPlainSocketImpl.connect (AbstractPlainSocketImpl.java:188) en java.net.PlainSocketImpl.connect (PlainSocketImpl.java:172) en java.net.SocksSocketImpl.connect (SocksSocketImpl.java:392) en java.net.Socket.connect (Socket.java:589) en org.apache.http.conn.scheme.PlainSocketFactory.connectSocket (PlainSocketFactory.java:117) en org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection (DefaultClientConnectionOperator.java:177) en org.apache.http.impl.conn.ManagedClientConnectionImpl.open (ManagedClientConnectionImpl.java:304) en org.apache.http.impl.client.DefaultRequestDirector.tryConnect (DefaultRequestDirector.java:611) en org.apache.http.impl.client.DefaultRequestDirector.execute (DefaultRequestDirector.java:446) en org.apache.http.impl.client.AbstractHttpClient.doExecute (AbstractHttpClient.java:882) en org.apache.http.impl.client.CloseableHttpClient.execute (CloseableHttpClient.java:82) en org.apache.http.impl.client.CloseableHttpClient.execute (CloseableHttpClient.java:55) en org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient $ Runner.sendUpdateStream (ConcurrentUpdateSolrClient.java:312) en org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient $ Runner.run (ConcurrentUpdateSolrClient.java:185) en org.apache.solr.common.util.ExecutorUtil $ MDCAwareThreadPoolExecutor.lambda $ execute $ 0 (ExecutorUtil.java:229) en java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1142) en java.util.concurrent.ThreadPoolExecutor $ Worker.run (ThreadPoolExecutor.java:617) en java.lang.Thread.run (Thread.java:745) [INFO] | 08-04-2017 14:47:56 | | O.a.s.u.p.LogUpdateProcessorFactory.finish | bc1911d6-e785-4b23-9730-127b3a751df5 | [INDEXING_TEST_shard3_replica2] webapp = / Camino de Solr = / update queryId = bc1911d6-e785-4b23-9730-127b3a751df5 params = {update.distrib = TOLEADER & distrib.from = devm50: 8091 / Solr / INDEXING_TEST_shard2_replica1 / & wt = javabin & version = 2 } {Add = [6042]} 0 14 [INFO] | 08-04-2017 14:47:56 | | o.apache.solr.core.SolrCore.Request.preDecorateResponse | Fa6f4db7-542e-41c2-8287-b0c3b9e0a272 | {Update.distrib = TOLEADER & distrib.from = http: // devm50: 8091 / Solr / INDEXING_TEST_shard2_replica1 / & wt = javabin & version = 2 & queryId = fa6f4db7-542e-41c2-8287-b0c3b9e0a272} [INFO] | 08-04-2017 14:47:56 | | O.a.s.u.p.LogUpdateProcessorFactory.finish | Fa6f4db7-542e-41c2-8287-b0c3b9e0a272 | [INDEXING_TEST_shard3_replica2] webapp = / Camino de Solr = / actualizar queryId = fa6f4db7-542e-41c2-8287-b0c3b9e0a272 params = {update.distrib = TOLEADER & distrib.from = http: // devm50: 8091 / Solr / INDEXING_TEST_shard2_replica1 / & wt = javabin & version = 2 } {Add = [6044]} 0 4 [INFO] | 08-04-2017 14:47:56 | | o.apache.solr.core.SolrCore.Request.preDecorateResponse | fba0324e-15d1-4752-ae05-fd67af5327e9 | {Update.distrib = TOLEADER & distrib.from = http: // devm50: 8091 / Solr / INDEXING_TEST_shard2_replica1 / & wt = javabin & version = 2 & queryId = fba0324e-15d1-4752-ae05-fd67af5327e9} [INFO] | 08-04-2017 14:47:56 | | O.a.s.u.p.LogUpdateProcessorFactory.finish | Fba0324e-15d1-4752-ae05-fd67af5327e9 | [INDEXING_TEST_shard3_replica2] webapp = / Camino de Solr = / update queryId = fba0324e-15d1-4752-ae05-fd67af5327e9 params = {update.distrib = TOLEADER & distrib.from = http: // devm50: 8091 / Solr / INDEXING_TEST_shard2_replica1 / & wt = javabin & version = 2 } {Add = [6045]} 0 3 [INFO] | 08-04-2017 14:47:56 | | o.apache.solr.core.SolrCore.Request.preDecorateResponse | 9b57afc4-f906-4985-97a1-e3544e8feaec | {Update.distrib = TOLEADER & distrib.from = http: // devm50: 8091 / Solr / INDEXING_TEST_shard2_replica1 / & wt = javabin & version = 2 & queryId = 9b57afc4-f906-4985-97a1-e3544e8feaec} root root /etc/udev/rules.d/99-tty-acm.rules KERNEL=="ttyACM0", OWNER="mynonrootuser", MODE=0660 ttyacm {{}}} {{}}} {{}} GROUP="ttyacm"

答案 1 :(得分:1)

通常我会通过使用以下技巧来解决这个问题

statObj.chatObj = JSON.parse(JSON.stringify(statList));

我不是说这是一个很好的做法,但是通过这种方式,我确保创建的对象在内存中拥有它自己的地址。

Object.assign()的问题在于它无法使用嵌套属性,无论如何,创建的对象都是可变的。