Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从Google电子表格获取数据时handlebar.js中的条件 我在哪里_Javascript_Jquery_Css_Google Sheets_Handlebars.js - Fatal编程技术网

Javascript 从Google电子表格获取数据时handlebar.js中的条件 我在哪里

Javascript 从Google电子表格获取数据时handlebar.js中的条件 我在哪里,javascript,jquery,css,google-sheets,handlebars.js,Javascript,Jquery,Css,Google Sheets,Handlebars.js,我正在使用和handlebar.js从Google电子表格中提取与政治家声明相关的所有数据,然后将它们显示在页面上 问题 a)我从控制台从特定对象获取有效性的数据时遇到问题。当我使用console.log(data)时,我能够从Google电子表格中获取每个对象,但我无法仅从第一个或第三个对象获取有效性 控制台(单个对象) b)有语法问题,想知道如果语句(基于电子表格的数据)的有效性是真的、假的或未确认的与编写if/语句并使用jQuery的.css()相比,在把手中使用条件是否是更改元素边框颜色

我正在使用和handlebar.js从Google电子表格中提取与政治家声明相关的所有数据,然后将它们显示在页面上

问题 a)我从控制台从特定对象获取
有效性的数据时遇到问题。当我使用console.log(data)时,我能够从Google电子表格中获取每个对象,但我无法仅从第一个或第三个对象获取
有效性

控制台(单个对象) b)有语法问题,想知道如果语句(基于电子表格的数据)的
有效性
是真的、假的或未确认的与编写if/语句并使用jQuery的.css()相比,在把手中使用条件是否是更改元素边框颜色的最有效方法或.addClass()

尝试这样做(两者都不起作用)

{#if Facts.validity.TRUE }}
    <div class="trueContainer container">
{{else if Facts.validity.FALSE}}
    <div class="falseContainer container">
{{else Facts.validity.UNCONFIRMED}}
    <div class="falseContainer container">
{{/if}}

不知道我是否明白你的问题。要打印有效性,您可以控制台此
data.Facts.elements[i].validity
,其中i是元素长度的0,对于(b),您可以将有效性值附加为类,并将该类与相应的边框样式一起放在CSS中。类似于这样的
$('.container').eq(i).addClass(data.Facts.elements[i].validity)我今晚就试试
if (validity == true) {
     $(".container").css("border", "1px solid #2ECC40");
} else if (validity == unconfirmed) {
    $(".container").css("border", "1px solid #FFDC00");
} else (validity == false) {
    $(".container").css("border", "1px solid #FFDC00");
}
{#if Facts.validity.TRUE }}
    <div class="trueContainer container">
{{else if Facts.validity.FALSE}}
    <div class="falseContainer container">
{{else Facts.validity.UNCONFIRMED}}
    <div class="falseContainer container">
{{/if}}
<!-- This is where the template for facts goes -->
<script id="poli" type="text/x-handlebars-template">
<div class="container">
    <p class="claim">Claim: {{name}} has said "{{statement}}"</p>
    <p class="explanation">This statement is {{validity}}. This is reason number one and a detailed explanation. <a href=""><sup class="unconfirmed">1</sup></a> This is reason number two with a detailed explanation. <a href=""><sup class="unconfirmed">2</sup></a> And this is {{explanation}} <a href=""><sup class="unconfirmed">3</sup></a> These fact checking boxes should always include 2-3 cited explanation, written by the reporter and linked to a file on DocumentCloud or Soundcloud.</p>
</div>
</script>

var public_spreadsheet_url = "https://docs.google.com/spreadsheets/d/1glFIExkcuDvhyu5GPMaOesB2SlJNJrSPdBZQxxzMMc4/pubhtml";

      $(document).ready( function() {
        Tabletop.init( { key: public_spreadsheet_url,
                         callback: showInfo,
                         parseNumbers: true } );
      });
      function showInfo(data, tabletop) {
        var source   = $("#poli").html();
        var template = Handlebars.compile(source);

        // The actual name of the sheet, not entire .csv
        $.each( tabletop.sheets("Facts").all(), function(i, fact) {
          var html = template(fact);

          // You need an element with this id or class in your HTML
          $("#poli-list").append(html);
          console.log(data);
        });
    }
/*----------------------------------
MAIN STYLES
----------------------------------*/

.trueContainer {
    border: 2px solid #2ECC40;
}

.falseContainer {
    border: 2px solid #FF4136;
}

.unconfirmedContainer {
    border: 2px solid #FFDC00;
}

.container {
    margin-top: 1%;
    padding: 0.5%;
    width: 50%;
}

.claim, sup {
    font-family: 'Lato', sans-serif;
    font-weight: 900;
}

sup {
    padding: 2px;
}

a {
    text-decoration: none;

}

.explanation {
    font-family: 'Lato', sans-serif;
    font-weight: 400;
    line-height: 28px;
    letter-spacing: 0.025px;
}

.true {
    color: #2ECC40;
}

.false {
    color: #FF4136
}

.unconfirmed {
    color: #FFDC00;
}