问题描述
对于这种类型的开发,我是超级新手,所以请在这里忍受。 一切都陷入不确定的境地,如果我尝试清空,那就是:if(typeof choices =='')。我收到此错误:“ JSON在位置0处出现意外令牌u”。 我可能没有足够的信息来帮助您,但目前为止就这么多,所以我只需要问您要解决的问题就可以告诉我。 在下面找到导致问题的代码部分:
function get_totals_for(type) {
var result = 0;
$(".component").each(function(index) {
console.log($(this));
var choices = $(this).data('choices');
if(typeof choices == 'undefined') {
result += 0;
} else {
choices = JSON.parse(choices);
console.log(choices);
switch(type) {
case 'kolhydrater':
result += ((choices.kolhydrater) ? choices.kolhydrater : 0);
break;
case 'fett':
result += ((choices.fett) ? choices.fett : 0);
break;
case 'kcal':
result += ((choices.kcal) ? choices.kcal : 0);
break;
case 'protein':
result += ((choices.protein) ? choices.protein : 0);
break;
}
}
});
return (result).toFixed(2);
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)