我正在尝试将csv转换为希腊语中1.5角+离子上的数组。 我正在使用ng-csv。 我到目前为止做了什么:
HTML:
<ng-csv-import
class="import"
content="csv.content"
header="csv.header"
header-visible="csv.headerVisible"
separator="csv.separator"
separator-visible="csv.separatorVisible"
result="csv.result"
encoding="csv.encoding"
encoding-visible="csv.encodingVisible"></ng-csv-import>
我的控制器是:
.controller('SettingsCtrl', function ($scope,$parse) {
$scope.csv = {
content: null,
header: true,
headerVisible: true,
separator: ',',
separatorVisible: true,
result: null,
encoding: 'Windows-1255',
encodingVisible: true
};
还有什么办法可以将对象作为数组。
答案 0 :(得分:1)
将控制器中的代码修改为
$scope.csv = {
content: null,
header: true,
headerVisible: true,
separator: ',',
separatorVisible: true,
result: null,
encoding: 'ISO-8859-1',
encodingVisible: true,
accept:".csv"
};
和你的HTML
<ng-csv-import content="csv.content"
header="csv.header"
separator="csv.separator"
result="csv.result"
accept="csv.accept">
</ng-csv-import>
$ scope.csv.result现在将是一个对象数组
答案 1 :(得分:-1)
$scope.csv.result
将包含转化后的结果数组。用户从浏览按钮中选择CSV文件后,将填充该文件。所以,如果你只是想对屏幕进行数据转储:
<div ng-if="csv.content">
{{csv.content}}
</div>
当你填充它时,你想做更多的事情是很好的,所以你可以设置一个手表
// (in controller)
$scope.$watch(
function() { return $scope.csv.content; },
function(newValue, oldValue) {
// do something on change
}
);