【发布时间】:2016-01-09 08:26:16
【问题描述】:
我是 AngularJS 的初学者,现在我正在构建简单的应用程序。
我有一些这样的 HTML 代码
<table class="table" ng-repeat="(attr, assets) in customize.product.attributes">
<tr>
<th colspan="2">{{attr}}</th>
</tr>
<tr ng-repeat="asset in assets">
<td>
{{asset}}
</td>
<td>
<file-uploader class="form-control"
image-width="{{galleryConfigs.width}}"
image-height="{{galleryConfigs.height}}"
image-crop-width="{{galleryConfigs.width}}"
image-crop-height="{{galleryConfigs.height}}"
max-size="5000"
allowed-extensions="png,jpeg,jpg"
result-model="customize.assets[attr][asset]">
</file-uploader>
</td>
</tr>
</table>
这是我的代码 JS
$scope.create = function(published){
var published = published || false,
customize = angular.copy($scope.customize);
if(published)
customize.published = true;
dataProvider.Customize.save(customize).$promise
.then(function(_customize){
if(!_customize) throw 'Error System';
toast.create({content:'Succes', className:'success'});
$state.go('pos.product.customize.show',{customizeId:_customize.id});
}).catch(function (error){
$log.error(error);
});
};
当我推送数据时,数据存储如下所示
"assets" : {
"part 1" : {
"black" : [
"/file/c36a3297-11bb-4028-8cb7-d750b98436ec.png",
"/file/4a6ec1ed-c3b1-48f9-84c0-61dd0f6da08a.png",
"/file/c66ac97a-18be-4e79-9ec1-ca67ab37d3f3.png"
],
"red" : [
"/file/c36a3297-11bb-4028-8cb7-d750b98145ec.png",
"/file/4a6ec1ed-c3b1-48f9-8cb7-61dd0f6da07a.png",
"/file/c66ac97a-18be-4e79-8cb7-ca67ab37d3c3.png"
]
}
}
即使我想用如下所示的结构保存数据
"assets" : {
"part 1" : {
"black" :"/file/a11c553f-de74-48e2-93a0-6fc72a54fa9b.png",
"red" :"/file/a11c553f-de74-48e2-93a0-6fc72a54ga8c.png"
}
}
有什么办法吗?
【问题讨论】:
-
你的阵列在哪里?
-
@CharlieH 再次看到我的问题,请帮忙
-
您只需要数组中的一个元素吗?
-
这意味着黑色数组中的三个元素需要三个单独的条目
-
@CharlieH 是的,我只需要一个元素,黑色数据不是数组而是对象
标签: javascript angularjs underscore.js lodash