Если вы хотите очистить данные только для того, чтобы возвращать данные оценки json внутри дерева, вы можете очистить их.
如果 想要 清空, 只 需要 判断 返回 的 JSON 里面 的 某 值 有 木 有 数据, 然后 清空 就 可以 啦.
function selectRegion(){
$("#saleRegionSelect").autocomplete({
source: function (request, response) {
var cityId=$("[name='city']").val();
var oppType=$("[name='primaryBiz']:checked").val();
var site= $.trim($("#channel").val());
if(oppType==undefined){
return false;
}
if(site==undefined){
return false;
}
$.ajax({
url: rootPath + "ajax/regionByCityAndSite",
dataType: "json",
type: "post",
data: {
region: request.term,
city:cityId,
site:site,
oppType:oppType
},
success: function (data) {
if (!data.rows) { //Look at this line
$('#saleRegionSelect').val('');//clear
$('#saleRegion').val(''); //clear
response(($.map([], function (item) {
return {}
})));
} else {
response(($.map(data.rows, function (item) {
return {
label: item.region + ($.trim(item.saleName)==""?"":' (' + item.saleName + ')'),
value: item.region + ($.trim(item.saleName)==""?"":' (' + item.saleName + ')'),
id: item.id
}
})));
}
}
})
},
minLength: 1,
select: function (event, ui) {
$("#saleRegion").val(ui.item.id);
}
});
}
=> json:
{
"status": 200,
"message": "查询数据成功!",
"rows": [{
"id": "678140138089353216",
"oppType": 10,
"saleId": "201402201431456839e855",
"saleName": "陈",
"creator": "zhangdanling",
"createTime": "2015-12-19 17:26:29",
"modifier": "zhangdanling",
"modifyTime": "2015-12-22 11:11:35",
"cityId": 147,
"site": 1,
"region": "测试测试",
"remark": ""
}, {
"id": "678847511099609088",
"oppType": 10,
"saleId": "201402201431456839e855",
"saleName": "陈",
"creator": "zhangdanling",
"createTime": "2015-12-21 16:17:23",
"modifier": "zhangdanling",
"modifyTime": "2015-12-22 15:55:59",
"cityId": 147,
"site": 1,
"region": "测试一区",
"remark": ""
}, {
"id": "678910954649423872",
"oppType": 10,
"saleId": "201402201431456839e855",
"saleName": "陈",
"creator": "zhangdanling",
"createTime": "2015-12-21 20:29:30",
"modifier": "zhangdanling",
"modifyTime": "2015-12-21 20:29:30",
"cityId": 147,
"site": 1,
"region": "测试区域三",
"remark": ""
}, {
"id": "679596181579374592",
"oppType": 10,
"saleId": "201407081036237ccfe9dc",
"saleName": "张",
"creator": "zhangdanling",
"createTime": "2015-12-23 17:49:05",
"modifier": "zhangdanling",
"modifyTime": "2015-12-23 17:49:14",
"cityId": 147,
"site": 1,
"region": "测试一下",
"remark": ""
}, {
"id": "680322348053700608",
"oppType": 10,
"saleId": "201407081036237ccfe9dc",
"saleName": "张",
"creator": "SYS_INIT",
"createTime": "2015-12-25 17:54:20",
"modifier": "SYS_INIT",
"modifyTime": "2015-12-25 17:54:20",
"cityId": 147,
"site": 1,
"region": "测试一下001",
"remark": ""
}, {
"id": "681308156487278592",
"oppType": 10,
"saleId": "201402201431456839e855",
"saleName": "陈",
"creator": "zhangdanling",
"createTime": "2015-12-28 11:11:56",
"modifier": "zhangdanling",
"modifyTime": "2015-12-28 11:11:56",
"cityId": 147,
"site": 1,
"region": "测试离职销售区域",
"remark": ""
}]
}