У меня есть ответ JSON следующим образом:
{
"Unidades": [
{
"Nome": "laskjdhflksjfg",
"Codigo": "11106600"
},
{
"Nome": "wertwertwertwer",
"Codigo": "11106601"
},
{
"Nome": "wertwertwertwer",
"Codigo": "11106602"
}
]
}
и я пытаюсь использовать загрузочный шрифт Angular-UI, делая это:
КОНТРОЛЛЕР
function TypeaheadCtrl($scope, $http) {
$scope.selected = undefined;
$scope.url = 'unidades/unidades-controler.asp'; //the response of json is from here
$http.get($scope.url).success(function (data, status) {
$scope.Unidades = data[0].Unidades;
}).error(function (data, status) {
$scope.response = 'Request failed';
});
}
HTML
<div ng-controller="TypeaheadCtrl">
<pre>Model: {{selected | json}}</pre>
<input type="text" ng-model="selected" typeahead="Unidade.Codigo as Unidade.Nome for Unidade in Unidades | filter:$viewValue | limitTo:8" class="form-control">
</div>
Моя проблема: мне нужно, чтобы <pre>Model: {{selected | json}}</pre>
отображало значение Unidade.Codigo
, и мне нужно, чтобы <input type="text" ng-model="selected" typeahead="Unidade.Codigo as Unidade.Nome for Unidade in Unidades | filter:$viewValue | limitTo:8" class="form-control">
отображало значение Unidade.Nome
. Как я могу это сделать?
Вот что я получил:
И это то, что мне нужно:
Я внес эти изменения, следуя этому примеру: p=preview, но все еще не работает:
HTML
<div class='container-fluid' ng-controller="TypeaheadCtrl">
<pre>Model: {{Selected| json}}</pre>
<input type="text" ng-model="Selected" typeahead="Unidade.Codigo as Unidade.Nome for Unidade in getUnidades($viewValue) | filter:$viewValue | limitTo:8" class="form-control" />
</div>
КОНТРОЛЛЕР
function TypeaheadCtrl($scope, $http) {
$scope.selected = undefined;
$scope.url = 'unidades/unidades-controler.asp'; //the response of json is from here
$http.get($scope.url).success(function (data, status) {
$scope.Unidades = data[0].Unidades;
}).error(function (data, status) {
$scope.response = 'Request failed';
});
$scope.getUnidades = function($viewValue) {
return $http.get($scope.Unidades).then(function(response){
return data;
});
};
}
ОШИБКА
GET http://localhost/[object%20Object],[object%20Object],[…t],[object%20Object],[object%20Object],[object%20Object],[object%20Object] 400 (Bad Request)
Я также пытался сделать это:
function TypeaheadCtrl($scope, $http) {
$scope.selected = undefined;
$scope.url = 'unidades/unidades-controler.asp'; //the response of json is from here
$scope.getUnidades = function($viewValue) {
return $http.get($scope.url).success(function (data, status) {
return data;
}).error(function (data, status) {
$scope.response = 'Request failed';
});
};
}
Но я получаю эту ошибку:
ReferenceError: response is not defined
response
равноundefined
в обратном вызове успеха есть толькоdata
иstatus
, но нет ответа - person dcodesmith   schedule 21.01.2014