0

我们正在显示基于“从和到日期”搜索显示的结果计数,我们面临的问题是,当结果为空时,结果显示为“-1”,但我们希望显示为“0”

html代码是

<div class="delete_grid" >

<form name="frmSearch" method="post" action="">
<input type="text"  id="post_at" name="post_at"  />  
<input type="text"  id="post_at_to_date" value=""name="post_at_to_date"  />
<input type="submit" name="search" value="search" id="searchButton">

</form>

</div>

javascript代码是

var gridOption={
    container : 'myGrid',
};

var mygrid=new Sigma.Grid(gridOption);
Sigma.Util.onLoad( Sigma.Grid.render(mygrid) );

$(".delete_grid").append("Number  of  Designs  Sold : "+mygrid.dataset.getSize());

我们正在使用 sigma 插件: http: //pastebin.com/ftfL6qnU

4

1 回答 1

0

Not sure where you're getting -1 exactly, I'm guessing here maybe: mygrid.dataset.getSize()?

In any case, you can probably use a ternary operator.
So let's say you need it there, use this: mygrid.dataset.getSize()<0?0:mygrid.dataset.getSize()

The complete line would become:

$(".delete_grid").append("Number  of  Designs  Sold : "+(mygrid.dataset.getSize()<0?0:mygrid.dataset.getSize()));
  • When mygrid.dataset.getSize() is less then 0, the value is set to 0.
    Otherwise, the value of mygrid.dataset.getSize() is used.
  • Notice that in the complete line, I wrapped the ternary operator in parentheses. It might not be strictly necessary, but when you're unsure or when it improves readability, I always prefer that.
于 2017-01-09T06:12:19.283 回答