推进多归因项目到一个数组JAVASCRIPT [英] Pushing a multiple-attributed item to an array JAVASCRIPT

查看:109
本文介绍了推进多归因项目到一个数组JAVASCRIPT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组列明如下:

I have an array set out like this:

var newCircles = [{
    num: 0,
    name: "title0",
    x: 280,
    y: 200,
    color: "#555555",
    r: 60
},
{
    num: 1,
    name: "title1",
    x: 480,
    y: 200,
    color: "#555555",
    r: 80
}];

和我试图把一套新的信息是这样的:

And I'm trying to push new set of information like this:

$(newCircles).push(', { num: "'+newCircles.length+'", name : "title "'+(newCircles.length)+'", x : "'+newCircles[chosenCircle].x+'", y : "'+newCircles[chosenCircle].y+'", color : "#7f38a7", r : "'+newCircles[chosenCircle].r+'" }');

但它不工作。任何人有什么建议吗?

But it's not working. Anyone have any suggestions?

推荐答案

您正在推动一个字符串到数组。
如果你想要把另一个对象入阵,那么这样做通过

you are pushing a string into the array. if you want to push another object into the array, then do so by

newCircles.push( {
  num: newCircles.length,
  name: 'title ' + newCircles.length,
  x: newCircles[chosenCircle].x,
  y: newCircles[chosenCircle].y,
  color : "#7f38a7",
  r: newCircles[chosenCircle].r
} );

这篇关于推进多归因项目到一个数组JAVASCRIPT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆