Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.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
Arrays 为什么数组保存最后的数据而不';t清除?_Arrays_Angularjs_Devextreme - Fatal编程技术网

Arrays 为什么数组保存最后的数据而不';t清除?

Arrays 为什么数组保存最后的数据而不';t清除?,arrays,angularjs,devextreme,Arrays,Angularjs,Devextreme,我有一个简单的AngularJs医疗卡应用程序 我有存储空间,并使用dx datagrid将其显示在我的home.html: 一张卡有很多记录,我从recordsArraybycardId getVardsRecordsByCardId: function (id, recordsArray) { if (recordsArray.length != 0) { for (var i = 0; i < recordsArray.length; i+

我有一个简单的
AngularJs
医疗卡应用程序

我有存储空间,并使用
dx datagrid
将其显示在我的
home.html

一张卡有很多记录,我从
recordsArray
by
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;

    }

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

也许有人知道我该怎么解决?谢谢你的回答

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

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

但这并没有什么帮助。

您应该在函数GetVardRecordsByCardId中初始化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;
}
getVardsRecordsByCardId:函数(id,recordsArray){
var cardsRecords=[];//在本地初始化阵列
如果(recordsArray.length!=0){
对于(var i=0;i
我想您只是想将使用array.concat的位置更改为array.push。@Mike Feltman,谢谢,我更改了它,但仍然不起作用。请注意,在不同的javascript范围内使用了两次
var jdskla
,因此实际上有两个不同的变量具有相同的属性name@charlietfl哦,你找错了,谢谢,但它仍然不起作用,我不知道为什么。如果你在不同的控制器中这样做,应该使用服务来存储数据哦,天哪,我在我的工厂里初始化了它,在我的方法内部初始化后,它起作用了,谢谢!
 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;
}