Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
307 views
in Technique[技术] by (71.8m points)

easyui下拉框的多出来一个0怎么去掉?

展开下拉框的样式如下:image.png

前端用的是easyui框架:

<td width="15%"><input class="easyui-combobox " data-options="valueField:'id',textField:'text',url:'include\getDictionarListById.php?type=140',method:'get',prompt:'请选择车辆类型'" name="sel_carmodel" id="sel_carmodel" ></td>

后端用的是php:

$sql="select dic_id as id ,rtrim(dic_value) as text from dictionary ".$where." order by weight ";
        $array=array();

        $result =$db->query($sql);
            if($result) {
                 $counts = sqlsrv_has_rows( $result);
                 if($counts>0) {
                     while( $r = sqlsrv_fetch_array( $result, SQLSRV_FETCH_BOTH)) {
                         if(empty($r['text'])){
                             continue;
                         }
                         array_push($array,$r);
                    }
                }
            }
        return $array;

打印出来的数组如下:
array(13) {
[0]=>
array(4) {

[0]=>
int(617)
["id"]=>
int(617)
[1]=>
string(6) "轿车"
["text"]=>
string(6) "轿车"

}
[1]=>
array(4) {

[0]=>
int(618)
["id"]=>
int(618)
[1]=>
string(9) "商务车"
["text"]=>
string(9) "商务车"

}
[2]=>
array(4) {

[0]=>
int(1136)
["id"]=>
int(1136)
[1]=>
string(9) "面包车"
["text"]=>
string(9) "面包车"

}
[3]=>
array(4) {

[0]=>
int(1419)
["id"]=>
int(1419)
[1]=>
string(9) "越野车"
["text"]=>
string(9) "越野车"

}
[4]=>
array(4) {

[0]=>
int(74)
["id"]=>
int(74)
[1]=>
string(21) "大型客车(>=20人)"
["text"]=>
string(21) "大型客车(>=20人)"

}
[5]=>
array(4) {

[0]=>
int(77)
["id"]=>
int(77)
[1]=>
string(22) "中型客车(10-19人)"
["text"]=>
string(22) "中型客车(10-19人)"

}
[6]=>
array(4) {

[0]=>
int(1420)
["id"]=>
int(1420)
[1]=>
string(45) "小型客车(<=9人,但不包括微型客车)"
["text"]=>
string(45) "小型客车(<=9人,但不包括微型客车)"

}
[7]=>
array(4) {

[0]=>
int(1421)
["id"]=>
int(1421)
[1]=>
string(12) "微型客车"
["text"]=>
string(12) "微型客车"

}
[8]=>
array(4) {

[0]=>
int(1422)
["id"]=>
int(1422)
[1]=>
string(34) "中型货车(>=4500kg,但<12000kg)"
["text"]=>
string(34) "中型货车(>=4500kg,但<12000kg)"

}
[9]=>
array(4) {

[0]=>
int(1423)
["id"]=>
int(1423)
[1]=>
string(21) "轻型货车(<4500kg)"
["text"]=>
string(21) "轻型货车(<4500kg)"

}
[10]=>
array(4) {

[0]=>
int(1454)
["id"]=>
int(1454)
[1]=>
string(30) "轻型非载货专项作业车"
["text"]=>
string(30) "轻型非载货专项作业车"

}
[11]=>
array(4) {

[0]=>
int(668)
["id"]=>
int(668)
[1]=>
string(30) "中型非载货专项作业车"
["text"]=>
string(30) "中型非载货专项作业车"

}
[12]=>
array(4) {

[0]=>
int(1424)
["id"]=>
int(1424)
[1]=>
string(6) "其他"
["text"]=>
string(6) "其他"

}
}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

是初始化的时候有一个默认值的问题:由$("#sel_carmodel").combobox('setValue',0);修改为$("#sel_carmodel").combobox('setValue',"");就可以了。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...