javascript - js concat 方法 在RN中使用的疑问
PHP中文网
PHP中文网 2017-04-11 11:18:30
[JavaScript讨论组]
console.log('这是的订单',this.state.page);
if(this.state.page>1) {
     data=this.state.dataSource;
     console.log('源数据',data);
     data.concat(responseData.data);
     for(i in responseData.data){
      data.push(responseData.data[i]);
      }
     console.log('最后数据',data);                   

源数据

[
        {
            "article_id": "24",
            "title": "不锈钢生锈的几大因素?",
            "platform": "pc",
            "type": "1",
            "node_id": "23",
            "author": "",
            "pubtime": "1459987200",
            "uptime": "1460443639",
            "level": "1",
            "ifpub": "true",
            "pv": "0",
            "disabled": "false",
            "content": "bd0f9369367d341d6ac9894bc6ac488a",
            "seoTitle": null,
            "keywords": null,
            "description": null
        },
        {
            "article_id": "25",
            "title": "不锈钢为什么也会带磁?",
            "platform": "pc",
            "type": "1",
            "node_id": "23",
            "author": "",
            "pubtime": "1460340000",
            "uptime": "1460443631",
            "level": "1",
            "ifpub": "true",
            "pv": "0",
            "disabled": "false",
            "content": "b09a8ed49aeea2c7ddd9daf407adf6d5",
            "seoTitle": null,
            "keywords": null,
            "description": null
        },
        {
            "article_id": "21",
            "title": "工业物联网发展必须克服的五大挑战导读",
            "platform": "pc",
            "type": "1",
            "node_id": "22",
            "author": "",
            "pubtime": "1459900800",
            "uptime": "1460443610",
            "level": "1",
            "ifpub": "true",
            "pv": "0",
            "disabled": "false",
            "content": "1c8a9da6c28f8e9b7cb5957a8cc29e1b",
            "seoTitle": null,
            "keywords": null,
            "description": null
        },
        {
            "article_id": "18",
            "title": "拼钢网:钢铁融入互联网 小平台聚合大订单",
            "platform": "pc",
            "type": "1",
            "node_id": "22",
            "author": "",
            "pubtime": "1460243880",
            "uptime": "1460443544",
            "level": "1",
            "ifpub": "true",
            "pv": "0",
            "disabled": "false",
            "content": "09730766650fa37ab73bab9d89f96b35",
            "seoTitle": null,
            "keywords": null,
            "description": null
        },
        {
            "article_id": "27",
            "title": "五类材质不同的不锈钢,知道有啥区别吗?",
            "platform": "pc",
            "type": "1",
            "node_id": "23",
            "author": "",
            "pubtime": "1460332800",
            "uptime": "1460443378",
            "level": "1",
            "ifpub": "true",
            "pv": "0",
            "disabled": "false",
            "content": "f9e64ffff2136fec06b31b621cd86854",
            "seoTitle": null,
            "keywords": null,
            "description": null
        },
        {
            "article_id": "26",
            "title": "不锈钢管承受压力计算公式",
            "platform": "pc",
            "type": "1",
            "node_id": "23",
            "author": "",
            "pubtime": "1460332800",
            "uptime": "1460443287",
            "level": "1",
            "ifpub": "true",
            "pv": "0",
            "disabled": "false",
            "content": "1290da515f3b5b3ba2d874b71683a08b",
            "seoTitle": null,
            "keywords": null,
            "description": null
        },
        {
            "article_id": "23",
            "title": "直径De、DN、D、d、Φ含义、区别",
            "platform": "pc",
            "type": "1",
            "node_id": "23",
            "author": "",
            "pubtime": "1460332800",
            "uptime": "1460443082",
            "level": "1",
            "ifpub": "true",
            "pv": "0",
            "disabled": "false",
            "content": "e7c3038f02916e4d56881055848d720c",
            "seoTitle": null,
            "keywords": null,
            "description": null
        },
        {
            "article_id": "22",
            "title": "4月201走势预测!",
            "platform": "pc",
            "type": "1",
            "node_id": "22",
            "author": "",
            "pubtime": "1460419200",
            "uptime": "1460443029",
            "level": "1",
            "ifpub": "true",
            "pv": "0",
            "disabled": "false",
            "content": "5e737191673b2cdf5a9b92bd9c9866c2",
            "seoTitle": null,
            "keywords": null,
            "description": null
        },
        {
            "article_id": "20",
            "title": "钢市现小狂潮!是需求“真”回暖?",
            "platform": "pc",
            "type": "1",
            "node_id": "22",
            "author": "",
            "pubtime": "1460073600",
            "uptime": "1460442838",
            "level": "1",
            "ifpub": "true",
            "pv": "0",
            "disabled": "false",
            "content": "2a904c350a5b6e60a39d734a08cae763",
            "seoTitle": null,
            "keywords": null,
            "description": null
        },
        {
            "article_id": "19",
            "title": "镍观察:伦镍持续震荡走势",
            "platform": "pc",
            "type": "1",
            "node_id": "22",
            "author": "",
            "pubtime": "1460332800",
            "uptime": "1460442738",
            "level": "1",
            "ifpub": "true",
            "pv": "0",
            "disabled": "false",
            "content": "2cd0c314ec830c7da5271e0d1d9b0bce",
            "seoTitle": null,
            "keywords": null,
            "description": null
        }
    ]

dataSource和responseData.data是完全相同的,问题为什么A处使用concat方法,却没有合并连个数组为新数组 B处使用for循环达到原始目的

PHP中文网
PHP中文网

认证0级讲师

全部回复(2)
高洛峰

你需要 data = data.concat(somenewdate)

只有push, pop, shift, unshift, splice 这几个方法会作用在原数组上。

test

迷茫

data.concat(responseData.data) 这句其实没有任何作用,你需要把 concat 的结果赋值给你的目标数组。
Array.prototype.concat

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号