我正在尝试根据$http
结果从 json 中获取动态数据,但这对我不起作用。我认为问题在于回调。我的意思是当我$http
继续运行时代码运行到 json 结果。这是我的 JavaScript 代码:
var operation_types = operation_types = [
{nav_id: 1, nav_name: "Validation", nav_src: "validation", nav_href: "validation_list"},
{nav_id: 2, nav_name: "Guests", nav_src: "guests", nav_href: "guests_list"}
];
angular.module("mainApp", ["kendo.directives"])
.controller("HomepageCtrl", function ($scope,$http) {//Homepage
/*receive user properties*/
$http({
url: 'API/v1/User/GetUserInfo',
method: "GET",
headers: { 'Content-Type': 'application/json' }
}).success(function (data, status, headers, config) {
if (data.Code != 1) {
$scope.error = "Please enter valid username and password!";
} else {
console.log(data);
if(data.viewGuest==true&&data.viewValidation==true){
$scope.source =operation_types;
}else if(data.viewGuest==false){
source = operation_types[0];
}else if(data.viewValidation==false){
source = operation_types[1];
}
//window.location.href = "homepage.html";
}
}).error(function (data, status, headers, config) {
$scope.error = "There are problems with connection to server. Status:" + status + " Please, try to connect later.";
$scope.validationClass = "invalid";
});
$scope.source =operation_types;
})
这是我的 html 代码的相关片段(使用 kendo ui):
<kendo-mobile-list-view k-data-source="source">
<div class="product" k-template>
<a href="\#{{dataItem.nav_href}}">
<img src="images/{{dataItem.nav_src}}.jpg" alt="{{dataItem.nav_name}} image" class="pullImage"/>
<h3>{{dataItem.nav_name}}</h3>
</a>
</div>
</kendo-mobile-list-view>
有人知道如何用角度来做吗?