我对角很陌生,并试图从built.io类中获取数据,并将其添加到$scope中。我已经完成了所有最初的Egghead示例和AngularJS教程,但还没有解决这个问题。控制台显示返回了json,但是我将这个json添加到$scope的尝试没有成功。我想我应该用一个承诺来做这件事,并且在没有运气的情况下尝试了好几次。基本的html是:
<!doctype html>
<html ng-app="Built">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script src="https://raw.githubusercontent.com/raweng/built.io-geoquery-playground/master/js/builtio.js"></script>
<script src="builtapp.js"></script>
<link rel="stylesheet" href="bootstrap.css">
<script>
Built.initialize('blt90ca3ef1fcb6f354', 'CIC001');
</script>
</head>
<body ng-controller="MainCtrl">
<div>
<div ng-repeat="client in clients">
{{ client.get('name') }}
</div>
</div>
</body>
</html>而js:
angular.module('Built', [])
.controller('MainCtrl', function($scope) {
$scope.client = null;
var myQuery = new Built.Query('Client');
myQuery.exec({
onSuccess: function(data) {
// projects is array of Built.Object
// here's the object we just created
$scope.clients = data;
},
onError: function(err) {
// error occured
}
});
});我创造了一个小提琴:https://jsfiddle.net/o2oxuz12/9/
刚刚更新了小提琴,包括一个显示一项数据的警报。
发布于 2015-03-24 02:49:44
如果其他人遇到同样的问题,我终于在这里找到了一个答案:AngularJS view not reflecting $scope.model, though data is being set。
query.exec({
onSuccess: function(clients) {
// projects is array of Built.Object
// here's the object we just created
$scope.$apply(function(){
$scope.clients = clients;
});
}
})最新的小提琴。https://jsfiddle.net/o2oxuz12/10/
我会在几天内不回答这个问题,因为我认为我找到的解决方案有点麻烦,有人可能会有一个更好的答案。
发布于 2015-03-23 06:40:19
angular.module('Built', [])
.controller('MainCtrl', function($scope) {
$scope.client = null;
var myQuery = new Built.Query('Client');
myQuery.modelType(Built.Object.NONE);
myQuery.exec({
onSuccess: function(data) {
// projects is array of Built.Object
// here's the object we just created
$scope.$apply(function(){
$scope.clients = data;
})
},
onError: function(err) {
// error occured
}
});
});https://stackoverflow.com/questions/29203614
复制相似问题