我完全正确地收到了我的胡子模板的输出,但是当我尝试使用JSON.parse()
对其进行编码时,它将输出[object Object]
。我不知道为什么?
第一输出:
{Inhalt:Array(27)} Inhalt:Array(27)0:begin:“08.03.2018”can_remove:true creator:“test”creator_date:“06.03.2018 08:18”end:“22.03.2018”est: “标准”id:27注释:“utc test”status_accepted:false status_none:true status_progress:false status_rejected:false status_removed:false time_from:“08:00”time_until:“11.00”work:“Kranken- und Altenpflegehelfer / in”worker :58 proto(这里是__之前和之后):Object
我的代码:
function getFrame() {
$.when(
$.ajax("mustache/templates/Liste/iFrame.mustache"),
$.ajax({
method: "POST",
url: "lister.php",
dataType: "JSON",
cache: false
}))
.done(function(tpl, data) {
var template = tpl[0];
var renderdata = data[0];
console.log(renderdata);
var rendered = Mustache.render(template,renderdata);
$('#frame').html(rendered);
let encoder = JSON.parse(data[0]);
console.log(encoder);
let startDate = encoder.Inhalt.begin;
let startTime = encoder.Inhalt.time_from;
let endDate = encoder.Inhalt.end;
let endTime = encoder.Inhalt.time_until;
let id = encoder.Inhalt.id;
var mergedBegin = startDate + " " + ClientOffset + " " + startTime;
var mergedEnd = endDate + " " + ClientOffset + " " + endTime;
var stillUtcBegin = moment.utc(mergedBegin).toDate();
var stillUtcEnd = moment.utc(mergedEnd).toDate();
var localBegin = moment(stillUtcBegin).local().format('DD-MM-YYYY HH:mm');
var localEnd = moment(stillUtcEnd).local().format('DD-MM-YYYY HH:mm');
console.log(id + ":begin: " + localBegin);
console.log(id + ":end: " + localend);
});
};
function ConvertUtcOffset(offset) {
let prefix = Math.floor(offset/60);
let postfix = offset%(60);
if (prefix >= 0 && prefix < 10) {
prefix = "0"+prefix;
} else
if (prefix < 0 && prefix > -10) {
prefix = "-0"+Math.Abs(prefix);
}
if (postfix >= 0 && postfix < 10) {
postfix = "0"+postfix;
}
return prefix + ":" + postfix;
};
我尝试将传入时间(UTC)编辑为用户本地时间。
我希望你能帮助我:)
也许你想要做的是字符串化吗?
// data: Serialized Array of objects (Names & Values).
console.log(data);
console.log('3. Stringify this Serialized Array of objects (Names & Values)');
// Stringify Serialized Array of objects.
data = JSON.stringify(data);