我正在尝试为数据容器设置DTM数据层。如果存在其单个名称容器,则输出按预期工作。
booking:{
unit:{
name: "Tony"
age: "45"
country: "China"
}
}
但是,当其大于1.时,不确定如何循环使用此格式的元素。
booking: {
unit:{
0:{
name: "Alex"
age: "32"
country: "Japan"
},
1:{
name: "Tony"
age: "45"
country: "China"
}
}
}
HTML:
<div id="data-container">
<div class="name-container">
<div class="name">Alex</div>
<div class="age">32</div>
<div class="country">Japan</div>
</div>
<div class="name-container">
<div class="name">Tony</div>
<div class="age">45</div>
<div class="country">China</div>
</div>
</div>
JS:
var name = $('.name-container .name').text(),
age = $('.name-container .age').text(),
country = $('.name-container .country').text();
let testLayer = {
booking: {
unit:{
name: name,
age: age,
country: country
}
}
};
DTM.setDataLayer(testLayer);
答案 0 :(得分:0)
您应该使用Array对象来设置DispatchQueue.global(qos: .background).async {
if let url = URL(string: self.audioURL!),
let urlData = NSData(contentsOf: url) {
let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0];
let filePath="\(documentsPath)/tempFile.mp3"
print(filePath)
DispatchQueue.main.async {
urlData.write(toFile: filePath, atomically: true)
PHPhotoLibrary.shared().performChanges({
PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: URL(fileURLWithPath: filePath))
}) { completed, error in
if completed {
print("Video is saved!")
}
}
}
}
}
。
在示例.each()
中,此方法用于迭代jQuery对象和上下文选择器以定位所需的units
元素。
<div>
let testLayer = {
booking: {
unit: []
}
};
$('.name-container').each(function(index, element) {
testLayer.booking.unit.push({
name: $(element).find('.name').text(),
age: $(element).find('age').text(),
country: $(element).find('country').text()
})
});
console.log(testLayer)