Я пытаюсь выполнить пакетную загрузку нескольких PDF-файлов. Каждый файл с именем в определенном форматекак отлаживать угловую петлю
02-2015 HIP BS32
дата/трубопровода аббревиатура/место аббревиатуры.
Я запускаю файлы через цикл, чтобы сравнить сокращения с списком в базе данных. Затем я присваиваю эти свойства объекту до его передачи в контроллер API. Таблицы трубопроводов и местоположений настроены точно так же. Проблема, с которой я столкнулась, связана с конвейером. это где проблема,
$scope.pip = $scope.pipeLookup[matches[1]];
$scope.loc = $scope.locationLookup[matches[2]];
locationLookup сопрягает местоположени аббревиатур и поместить его в переменной $ scope.loc. Однако pipeLookup не работает. Конечно, это ошибка, потому что свойства конвейера не определены. Я не уверен, что я просто что-то смотрю. если требуется дополнительная информация, то дайте мне знать
$scope.companies = Company.query(function() { });
$scope.locations = Location.query(function() { });
$scope.pipes = Pipe.query(function() { });
$scope.selectCompany = function() {
var id = $scope.companyId.CompanyId
$http.get('/api/apiCompany/' + id)
.success(function (result) {
$scope.CompanyName = result.CompanyName
});
};//
$scope.pipeLookup = {};
$scope.locationLookup = {};
$scope.upload = function() {
var files = $scope.files;
if (files && files.length) {
for (var i = 0; i < files.length; i++) {
var file = files[i];
$scope.pipes.map(function (pip) {
$scope.pipeLookup[pip['PipeAb']] = pip;
});
$scope.locations.map(function (loc) {
$scope.locationLookup[loc['LocationAb']] = loc;
});
var matches = file.name.match(/^\d+\D\d+\s*?(\S*)\s*(\S*?)\./i);
$scope.pip = $scope.pipeLookup[matches[1]];
$scope.loc = $scope.locationLookup[matches[2]];
$upload.upload({
url: '/api/apiBatchPipeLine',
fields: {
'typeId': 1,
'companyId': $scope.companyId.CompanyId,
'documentDate': $scope.model.documentDate,
'pipeId': $scope.pip['PipeId'],
'pipeName': $scope.pip['PipeName'],
'locationId': $scope.loc['LocationId'],
'locationAb': $scope.loc['LocationAb']
},
file: file
}).progress(function (evt) {
var progressPercentage = parseInt(100.0 * evt.loaded/evt.total);
console.log('progress: ' + progressPercentage + '% ' + evt.config.file.name);
}).success(function (data, status, headers, config) {
console.log('file ' + config.file.name + 'uploaded. Response: ' +
JSON.stringify(data));
}).error(function (err, result) {
console.log(err, result);
});
}
}
$ scope.pipeLookup JSON
{"ANR ":{"$id":"1","PipeId":1,"PipeAb":"ANR ","PipeName":"Transcanada ANR Pipeline","Documents":null},"CGT ":{"$id":"2","PipeId":2,"PipeAb":"CGT ","PipeName":"Columbia Gulf Transmission","Documents":null},"CHA ":{"$id":"3","PipeId":3,"PipeAb":"CHA ","PipeName":"Enterprise Channel Pipeline","Documents":null},"FGT ":{"$id":"4","PipeId":4,"PipeAb":"FGT ","PipeName":"Energy Transfer Florida Gas Transmission","Documents":null},"GAB ":{"$id":"5","PipeId":5,"PipeAb":"GAB ","PipeName":"Enbridge Garden Banks Pipeline","Documents":null},"GLO ":{"$id":"6","PipeId":6,"PipeAb":"GLO ","PipeName":"American Midstream Gloria Pipeline","Documents":null},"GSO ":{"$id":"7","PipeId":7,"PipeAb":"GSO ","PipeName":"Boardwalk Gulf South Pipeline","Documents":null},"HIO ":{"$id":"8","PipeId":8,"PipeAb":"HIO ","PipeName":"Enterprise High Island Offshore System","Documents":null},"HIP ":{"$id":"9","PipeId":9,"PipeAb":"HIP ","PipeName":"American Midstream High Point Pipeline","Documents":null},"HPL ":{"$id":"10","PipeId":10,"PipeAb":"HPL ","PipeName":"Energy Transfer Houston Pipeline","Documents":null},"TEJ ":{"$id":"11","PipeId":11,"PipeAb":"TEJ ","PipeName":"Kinder Morgan Tejas Pipeline","Documents":null},"KIN ":{"$id":"12","PipeId":12,"PipeAb":"KIN ","PipeName":"Kinetica Partners Pipeline","Documents":null},"NGP ":{"$id":"13","PipeId":13,"PipeAb":"NGP ","PipeName":" Kinder Morgan Natural Gas Pipeline","Documents":null},"SER ":{"$id":"14","PipeId":14,"PipeAb":"SER ","PipeName":" Energy Transfer Sea Robin Pipeline Company ","Documents":null},"SNT ":{"$id":"15","PipeId":15,"PipeAb":"SNT ","PipeName":"Kinder Morgan Southern Natural Gas Company","Documents":null},"SRY ":{"$id":"16","PipeId":16,"PipeAb":"SRY ","PipeName":"MCPO Stingray Pipeline Company","Documents":null},"TGT ":{"$id":"17","PipeId":17,"PipeAb":"TGT ","PipeName":"Kinder Morgan Tennessee Gas Pipeline","Documents":null},"TET ":{"$id":"18","PipeId":18,"PipeAb":"TET ","PipeName":"Spectra Energy Texas Eastern Pipeline","Documents":null},"TXG ":{"$id":"19","PipeId":19,"PipeAb":"TXG ","PipeName":"Boardwalk Texas Gas Transmission","Documents":null},"TSC ":{"$id":"20","PipeId":20,"PipeAb":"TSC ","PipeName":"Williams Transcontinental Gas Pipeline","Documents":null},"TRK ":{"$id":"21","PipeId":21,"PipeAb":"TRK ","PipeName":"Energy Transfer Trunkline Gas Company","Documents":null},"VGS ":{"$id":"22","PipeId":22,"PipeAb":"VGS ","PipeName":"Targa Venice Gathering System","Documents":null}}
$ scope.locationLookup Json
{"VR16":{"$id":"1","LocationId":1,"LocationAb":"VR16","LocationName":"Location VR16","Documents":null},"MP140\t":{"$id":"2","LocationId":2,"LocationAb":"MP140\t","LocationName":"Location MP140","Documents":null},"BS32":{"$id":"3","LocationId":3,"LocationAb":"BS32","LocationName":"Location BS32","Documents":null},"MP46":{"$id":"4","LocationId":4,"LocationAb":"MP46","LocationName":"Location MP46","Documents":null},"DF78":{"$id":"5","LocationId":5,"LocationAb":"DF78","LocationName":"Location DF78","Documents":null},"UR56":{"$id":"6","LocationId":6,"LocationAb":"UR56","LocationName":"Location UR56","Documents":null}}
если я удалю. из регулярного выражения он не работает – texas697
var matches = file.name.match (/^\ d + \ D \ d + \ s *? (\ S *) \ s * (\ S *?)/i); – texas697
Какова ценность внутри матчей [1]? а также значения внутри '$ scope.pipeLookup'? попробуйте обернуть совпадения [1] в одиночных или двойных кавычках, таких как '$ scope.pipeLookup [" '"+ matches [1] +"' "]' – kachhalimbu