我的目标是让用户通过选择阵列中每个图像的位置来重新排序图像阵列。对于它们中的每一个,我都有一个显示图像的ng-repeat,还有一个选择下拉按钮,用户可以根据$ scope.stock.otherPicNames的长度为每个图像选择索引。
HTML:
import fileinput
import json
import csv
def flattify(d, key=()):
if isinstance(d, list):
result = {}
for i in d:
result.update(flattify(i, key))
return result
if isinstance(d, dict):
result = {}
for k, v in d.items():
result.update(flattify(v, key + (k,)))
return result
return {key: d}
total = []
for line in fileinput.input():
if(line.strip()):
line = json.loads(line)
line = flattify(line)
line = {'.'.join(k): v for k, v in line.items()}
total.append(line)
keys = set()
for d in total:
keys.update(d)
with open('result.csv', 'w') as output_file:
output_file = csv.DictWriter(output_file, sorted(keys))
output_file.writeheader()
output_file.writerows(total)
JS:
<div class="gallery_wrapper" ng-repeat="f in stock.otherPicNames">
<img ng-src="{{getImage(f)}}">
<div class="order_gallery">
<select ng-options="pos as obj.position for obj in position track by $index" ng-value="$index+1 " ng-model="f.position"></select>
</div>
</div>
我坚持要求取回用户选择的值并将其放在$ scope.choice数组或$ scope.position.position中,具体取决于每个图像。我不知道如何正确设置ng-options和ng-value。
任何建议表示赞赏。