gpt4 book ai didi

javascript - 在 ngTables 中,第三次运行 $scope.tableParams.reload() 导致 TypeError : Cannot set property '$data' of null

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:24:29 28 4
gpt4 key购买 nike

此错误与 ngTable 有关AngularJS 插件。

我似乎遇到了一个非常奇怪的错误。基本上,我可以毫无问题地运行 $scope.tableParams.reload() 两次,但是在第三次执行以及接下来的每一次执行时,我都会收到以下错误:

TypeError: Cannot set property '$data' of null at [removed]/ng-table.js:411:55

我相信这是所有相关代码,但如果有任何遗漏请告诉我:

$scope.lookupAddress = function(address){       
var url = 'https://blockchain.info/multiaddr?cors=true&active='+address;
$scope.loading = true;
$scope.clearTableData();
$http.get(url).success(function(data){
$scope.loading = false;
$scope.loaded = true;
$scope.loadError = false;
glob = data;

//I believe the next few for loops, and the assignment of transactions, is not relevant to finding the code. That being said, I've included it because bugs hide where you least expect it.
for (i = data.txs.length -1; i > -1; i-- ){
var inputAddr = [];
for (z = 0; z < data.txs[i]['inputs'].length; z++){
inputAddr.push(data.txs[i]['inputs'][z]['prev_out']['addr'])
}
var outputAddr = [];
for (z = 0; z < data.txs[i]['out'].length; z++){
outputAddr.push(data.txs[i]['out'][z]['addr'])
}
transactions[i] = {
'Hash' : data.txs[i]['hash'],
'Amount' : data.txs[i]['result'] / 100000000,
'Balance' : data.txs[i]['balance'] / 100000000,
'InputAddress' : inputAddr,
'OutputAddress' : outputAddr,
'Date' : timeConverter(data.txs[i]['time'])
};
};

//You can also ignore this too... probably.
$scope.output = {
'BTC' : data.wallet.final_balance / 100000000, //Response in satoshi, so have to divide.
'Address' : address,
'Total Received': data.addresses[0].total_received / 100000000,
'Total Sent': data.addresses[0].total_sent / 100000000,
'Transactions' : transactions
};
//Enables new data to be loaded, e.g. on a new address.
if ($scope.tableParams){
$scope.tableParams.reload();
}
data = transactions;
$scope.tableParams = new ngTableParams({
page: 1,
count: 5, // items per page
sorting: {
Date: 'desc'
}
}, {
total: transactions.length,
getData: function($defer, params) {
data = transactions;
var orderedData = params.sorting() ? $filter('orderBy')(data, params.orderBy()) : data;
$defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));

}
});
}).
error(function(data){
$scope.loadError = true;
});
}

$scope.clearTableData = function(){
transactions = [];
$scope.output = {}
if ($scope.tableParams){
$scope.tableParams.reload();
}
}

最佳答案

我知道这为时已晚,但我认为最好对寻求同一问题答案的其他人对此发表评论。

我也遇到了同样的问题,并按照以下 URL 中的示例设法解决了。

https://github.com/esvit/ng-table/blob/master/src/scripts/04-controller.js

我刚刚在“ngTableParams”实例创建后将以下代码行添加到我的代码中。

$scope.params.settings().$scope = $scope;

关于javascript - 在 ngTables 中,第三次运行 $scope.tableParams.reload() 导致 TypeError : Cannot set property '$data' of null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23374896/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com