使用JavaScript将null替换为字符串

时间:2019-06-06 13:20:37

标签: javascript jquery html css

有人知道为什么在程序末尾运行时if语句什么也不做吗?我想将null的返回值替换为no office,之后似乎无法运行它。

enter image description here

for (z = 0; z < items.length; z++) {
  var team = '<div class="row"><div class="col-sm-8"><p style="margin-bottom: 0px;">' + items[z].TeamName + '</p></div><div class="col-sm-4 office"><p style="margin-bottom: 0px;">' + items[z].Office + '</p></div></div>';
  var single = '<div class="row"><div class="col-sm-8"><p style="margin-bottom: 0px;">' + items[z].Title + '</p></div><div class="col-sm-4"><p class="office" style="margin-bottom: 0px;">' + items[z].Office +
    '</p></div></div>';

  if (items[z].Office == 'null') {
    $(".office").append('No office');
  }
}

<div class="row" style="padding-bottom: 10px;">
  <div class="col-md-6">
    <div>
      <div class="row title">
        <div class="col-md-8">
          <span>Single Users</span>
        </div>
        <div class="col-md-4" style="padding-left: 4px;">
          <span>Office</span>
        </div>
      </div>
      <div class="col-md-12 teamsSingles" style="padding-left:0px; border-right: solid 1px #DCE1E5;">
      </div>
    </div>
  </div>
  <div class="col-md-6">
    <div>
      <div class="row title">
        <div class="col-md-8">
          <span>Teams</span>
        </div>
        <div class="col-md-4" style="padding-left: 4px;">
          <span>Office</span>
        </div>
      </div>
      <div class="col-md-12 teamsTeams" style="padding-left:0px;">
      </div>
    </div>
  </div>
</div>

1 个答案:

答案 0 :(得分:-1)

删除空值附近的引号(并添加另一个=以检查类型,因此===而不是==)