繁体   English   中英

在 Oracle-jet 中隐藏一个 div

[英]Hide a div in Oracle-jet

我正在创建一个 Oracle-Jet 应用程序,其中我需要使用 ojet-lists。 我从 REST API 动态调用数据。 这是列表视图的屏幕截图- 列表的SS

如您所见,我有一些值,即 Sub-Category、Views 和 Change%。 问题是我只能隐藏第一个元素的 div,即咨询。 这是我调用 REST API 的 JS 代码和隐藏 div 的条件。

function practiceData() {
        $.getJSON("REST API").then(function (dataset) {

          $.each(dataset, function (index, value) {
            data5.push(value); // PUSH THE VALUES INSIDE THE ARRAY.
            arrow.push(value.change);
            console.dir("data",data5)
          console.log("value",value.change)
          console.log("arrow", arrow);
          arrow.forEach(function(value)
          {
              if (value == 0) {
                document.getElementById("triangle-up-small").style.display = 'none';
                document.getElementById("triangle-down-small").style.display = 'none';
                console.log("rgjak");
                console.log(value);
              } else if (value < 0) {

              //  $("#triangle-up-small").hide();
                console.log("hcdsb");
                console.log(value);
                document.getElementById("triangle-up-small").style.display = 'none';

              }
              else{
                // $("#triangle-down-small").hide();
               $("#triangle-up-small").hide();
                console.log("123");
                console.log(value);
              }
            });
          });
        });

    }

所有数组值都是数字,这是列表的 HTML 代码 -

<oj-list-view id="listview" aria-label="simple list" data="[[dataProvider5]]">
              <template slot="itemTemplate" data-oj-as="item">
                 <!-- <span class="avatar" data-bind="style: { backgroundImage: 'url(\'../images/dvt/' + item.data.id + '.png\')' }"></span>-->

                  <div class="oj-flex ">
                <div class="oj-sm-5 oj-flex-item"><span class="name"><a id="yo"><oj-bind-text value="[[item.data.subcategory]]"></oj-bind-text></a></span></div>
                <div class="oj-sm-1 oj-flex-item"><span class="oj-text-xs oj-text-secondary-color" style="float: right;"  ><oj-bind-text value="[[item.data.count]]"></oj-bind-text>views</span></div>
                 <div class="oj-sm-1 oj-flex-item" ><div id="triangle-up-small"style="float: right;"><span  id="text-green"><oj-bind-text value="[[item.data.change]]"></oj-bind-text>%</span></div></div>
                 <div class="oj-sm-1 oj-flex-item"><div id="vl"style="float: right;"><span  id="text-green"><oj-bind-text value="[[item.data.change]]"></oj-bind-text>%</span></div></div>
                 <div class="oj-sm-1 oj-flex-item"><div id="triangle-down-small"style="float: right;"><span  id="text-red" style="margin-left: 10px;margin-top:0px;"  ><oj-bind-text value="[[item.data.change]]"></oj-bind-text>%</span></div></div>
              </div>
              </template>
          </oj-list-view>

我已经尝试了所有方法,任何帮助表示赞赏。 提前感谢您的帮助。

您应该使用oj-bind-if有条件地显示/隐藏元素。 直接使用 jQuery/DOM api 与 DOM 交互不被认为是最佳实践。

正如@Sumedh Chakravorty 所提到的,这是该问题的工作代码。

<oj-list-view id="listview" aria-label="simple list" data="[[dataProvider5]]">
              <template slot="itemTemplate" data-oj-as="item">
                 <!-- <span class="avatar" data-bind="style: { backgroundImage: 'url(\'../images/dvt/' + item.data.id + '.png\')' }"></span>-->
                 <script>

                   </script>
                  <div class="oj-flex ">
                <div class="oj-sm-5 oj-flex-item"><span class="name"><a id="yo"><oj-bind-text value="[[item.data.subcategory]]"></oj-bind-text></a></span></div>
                <div class="oj-sm-1 oj-flex-item"><span class="oj-text-xs oj-text-secondary-color" style="float: right;"  ><oj-bind-text value="[[item.data.count]]"></oj-bind-text>views</span></div>
                <oj-bind-if test="[[item.data.change == '0']]">
                 <div class="oj-sm-1 oj-flex-item"><div id="vl"style="float: right;"><span  id="text-green"><oj-bind-text value="[[item.data.change]]"></oj-bind-text>%</span></div></div>
               </oj-bind-if>
                 <oj-bind-if test="[[item.data.change < '0']]">
               <div class="oj-sm-1 oj-flex-item"><div id="triangle-down-small"style="float: right;"><span  id="text-red" style="margin-left: 10px;margin-top:0px;"  ><oj-bind-text value="[[item.data.change]]"></oj-bind-text>%</span></div></div>
             </oj-bind-if>
              </div>
              </template>
          </oj-list-view>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM