<div class='click_work' ng-repeat="client in clientSearch.searchClients track by $index"
ng-click='setClientValue(client)'>{{client.name}}
</div>
首先,我们在前端页面写了一个 ng-repeat。
$scope.searchClientName = function (keywords) {
$scope.clientSearch={};
if (keywords == '') {
return
};
$.ajax({
url: '****?wd=' + keywords,
//dataType: 'jsonp',
//jsonp: 'cb', //回调函数的参数名(键值)key
// jsonpCallback: 'fun', //回调函数名(值) value
beforeSend: function () {
$scope.clientSearch.searchClientsOnloading={}
},
success: function (data) {
if (data == '') {
$scope.clientSearch.noSearchClients=keywords;
} else {
$scope.clientSearch.searchClientsOnloading=null;
$scope.clientSearch.searchClients = data;
}
},
error: function () {
$scope.clientSearch.errorSearchClients=keywords;
}
})
}
使用ajax请求数据,然后更新 repeat数据,但是视图里却没有实时更新,这是需要在更新数据后加上 $scope.$apply();刷新