Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Can';t替换数组中的项_Javascript_Angularjs - Fatal编程技术网

Javascript Can';t替换数组中的项

Javascript Can';t替换数组中的项,javascript,angularjs,Javascript,Angularjs,编写一个有角度的应用程序 在这段代码中,我试图替换数组中特定数字处的项 for (i=0;i<this.marked.length;i++) { this.index = this.marked[i].ind; this.newSongs[this.index] = this.marked[i].name; } 那么为什么结果是这样呢 ['name1', 2: 'name3'] 而不是: ['name1', 'name2', 'name3'] 对不起,伙计们,实际上

编写一个有角度的应用程序

在这段代码中,我试图替换数组中特定数字处的项

for (i=0;i<this.marked.length;i++) {
    this.index = this.marked[i].ind;
    this.newSongs[this.index] = this.marked[i].name;
}
那么为什么结果是这样呢

['name1', 2: 'name3']
而不是:

['name1', 'name2', 'name3'] 
对不起,伙计们,实际上是这个;
我不小心把它删掉了。这个问题没有解决

我想你只需要换个新的

this.index = this.marked[i]


Khalid和Joel给了你正确的提示。您需要使用:

this.index = this.marked[i].ind
这是给你的安格拉斯小提琴。希望这会有所帮助

函数SongCtrl($scope){
$scope.songs=[
{
工业:1,,
姓名:“泰西”
},
{
工业部:2,
名字:“吻我,我大便”
},
{
工业部:3,
名称:“马萨诸塞州”
}
];
$scope.replace=函数(索引,值){

对于(i=0;i我注意到我试图在循环中运行我的代码。因此,当我将其拉出时,它工作正常。

我不知道你的问题中是否有输入错误,你不是应该写:
this.index=this.marked[i].ind
?而不是
this.index=this.marked[i].
?不确定最后一个点。。抱歉,它实际上是
这个。标记为[i].ind
问题是索引出现在我的数组中。
this.index = this.marked[i].ind
this.index = this.marked[i].ind
function SongCtrl($scope) {
  $scope.songs = [
        {
            ind: 1,
            name: "Tessie"
        },
        {
            ind: 2,
            name: "Kiss Me I’m Shitfaced"
        },
        {
            ind: 3,
            name: "The State of Massachusets"
        }
    ];

    $scope.replace = function(index, value) {
        for (i=0;i<$scope.songs.length;i++) {
            var currentIndex = $scope.songs[i].ind;
            if(currentIndex == index) {
                 $scope.songs[i].name = value;
            }
        }
    }
}