新角度.如果这是一个非常简单的问题,请原谅.
无论如何将数组转换为字符串.我的控制器她的代码:
$scope.addRow = function addRow(){
$scope.filters.push({ 'Name':$scope.name, 'dept': $scope.dept, 'city':$scope.city});
$scope.name='';
$scope.dept='';
$scope.city='';
};
Run Code Online (Sandbox Code Playgroud)
现在,我想将此数据作为字符串发送到服务
我希望它的格式为"name,dept,city; name,dept,city".有什么办法吗?
服务代码如下所示:
$scope.submit = function() {
myService.submit({
filters :$scope.filters
}, function(response) {
$scope.response = response;
});
};
Run Code Online (Sandbox Code Playgroud)
我想将值传递给数组中"name,dept,city; name,dept,city"格式的过滤器.提前致谢.
您可以使用
angular.toJson(array);
Run Code Online (Sandbox Code Playgroud)
创建数组的json字符串.
编辑:
var array = [{name: 'misko', dept: '007', city: 'new york' }, {name: 'misko', dept: '007',city: 'new york'}];
function createStringByArray(array) {
var output = '';
angular.forEach(array, function (object) {
angular.forEach(object, function (value, key) {
output += key + ',';
output += value + ',';
});
});
return output;
}
var string = createStringFromArray(array);Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24068 次 |
| 最近记录: |