为什么数组保存最后的数据却不清除?

乌拉兹卡(Uladz kha)

我有AngularJs医疗卡的简单申请。

我有存储,并在home.html使用时显示dx-datagrid

在此处输入图片说明

一卡有很多纪录,我拿到卡的记录,从recordsArray通过cardId

 getVardsRecordsByCardId: function (id, recordsArray) {
        if (recordsArray.length != 0) {
            for (var i = 0; i < recordsArray.length; i++) {
                if (recordsArray[i].cardId === id) {
                    cardsRecords = cardsRecords.concat(recordsArray[i]);
                }
            }
        }

        return cardsRecords;

    }

现在,我的记录就在第三张卡中。我在按钮上添加了一个功能对其进行测试:

 var jdskla = [];
var localCardId = 0;
$scope.showCardDetails = {
    text: "",
    type: "default",
    icon: "preferences",
    onClick: function () {
        if ($scope.itemIdFromShowButton) {
            $location.path('/carddetail/' + $scope.itemIdFromShowButton);
            var jdskla =[];
            var jdskla = businessLogicOfMyApp.getVardsRecordsByCardId($scope.itemIdFromShowButton, $scope.recordsArray);
            console.log($scope.itemIdFromShowButton)
            console.log(jdskla);

        }
        else {
            alert("Error!!!");
        }
    }
};

在此处输入图片说明

1,3,1是cardId的和array的记录。但是,为什么array卡记录不清除并保存最后的数据?

可能有人知道我该如何解决?感谢您的回答!

PS我ng-view在我的应用程序中使用指令,我试图清除我array使用另一个按钮:

 $scope.backToGeneralPage = {
    text: "Back",
    onClick: function () {
        jdskla = [];
        $location.path('/');
    }
};

但这没有帮助。

亚历山大·科马罗夫(Alexander Komarov)

您应该在函数getVardsRecordsByCardId中初始化cardsRecords数组。

 getVardsRecordsByCardId: function (id, recordsArray) {
    var cardsRecords = []; // initialize array locally
    if (recordsArray.length != 0) {
        for (var i = 0; i < recordsArray.length; i++) {
            if (recordsArray[i].cardId === id) {
                cardsRecords.push(recordsArray[i]);
            }
        }
    }
    return cardsRecords;
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

为什么清除不清除?

为什么mysqli prepare语句不清除数据

为什么“清除”不清除整个屏幕?

为什么不清除模型值?

为什么flock不清除锁定文件?

为什么不清除datagridview?以及如何清除datagridView?

为什么os.system('cls')不清除最近的输出?

为什么通过 ColorAdjust 应用效果后画布不清除?

为什么不清除我的div?(JavaScript和Jquery)

为什么幻影引用入队后不清除?

为什么clearTimeout不清除此React组件中的超时?

为什么UserDefaults.standard.set不保存我的数组?从后台删除应用程序后,将清除数据

为什么Windows 10上的Netbeans 9(每夜)不清晰,而Windows 10上的Netbeans却不清晰?

为什么我的对象只保存最后的数据

Django不清除数据

为什么一个数组填充了数据,而另一个数组却不在控制台中:[]和[{..} {..}]给出了相同的数据集?

我不明白为什么最后阶段没有任何保存或追加数据操作

为什么当我输入匹配的数组编号却不匹配数组

为什么我的数据打印到工作表名称数组的最后一个索引?

为什么String尽管是字符数组,却不能作为“按引用传递”

为什么数组类型实现IList <T>却不具有Add()方法?

为什么ArrayLists可以存储不同的对象,而数组却不能呢?

为什么数组循环可以在 Python 中删除重复的条目,而 JS 却不能?

将文本设置为字符串后,为什么我的文本框不清除文本?

为什么 clear_output() 不清除 VS 代码中打印到 python 控制台的内容?

清除或不清除

为什么我的静态数组没有被 memset 清除?

Vue.js 为什么我的数组值被清除了?

为什么Left()返回0,而substring()却不