以下是我从API调用获得的JSON
library(shiny)
library(DT)
shinyApp(
ui = fluidPage(
radioButtons("action_selectiontype", "Selection type",
choices = c("single", "multiple"),
selected = "single", inline = TRUE),
DT::dataTableOutput("dt")
),
server = function(input, output) {
table <- reactive({datatable(iris,selection=input$action_selectiontype)})
output$dt <- DT::renderDataTable({
table()})
}
)
角度控制器JS:
[{"Status":"Success","Emailid":"john.doe@example.com","BookingCreateDate":"07/04/2015 8:25:14 PM","promocode":"SELF","promovalue":"100.000","BookingUniqId":"0","PromoDescription":"RoomsTonite promotional offer - Save Rs. 100/- on your hotel booking.","CreateDatetime":"2015-07-04 20:25:14","UserName":"Mr.Prakash Maheshwari"},{"Status":"Success","Emailid":"john.doe@example.com","BookingCreateDate":"07/04/2015 8:25:14 PM","promocode":"SELF","promovalue":"100.000","BookingUniqId":"0","PromoDescription":"RoomsTonite promotional offer - Save Rs. 100/- on your hotel booking.","CreateDatetime":"2015-07-04 20:25:14","UserName":"Mr.Prakash Maheshwari"},{"Status":"Success","Emailid":"john.doe@example.com","BookingCreateDate":"07/04/2015 8:25:14 PM","promocode":"SELF","promovalue":"100.000","BookingUniqId":"0","PromoDescription":"RoomsTonite promotional offer - Save Rs. 100/- on your hotel booking.","CreateDatetime":"2015-07-04 20:25:14","UserName":"Mr.Prakash Maheshwari"},{"Status":"Success","Emailid":"john.doe@example.com","BookingCreateDate":"07/04/2015 8:25:14 PM","promocode":"SELF","promovalue":"100.000","BookingUniqId":"0","PromoDescription":"RoomsTonite promotional offer - Save Rs. 100/- on your hotel booking.","CreateDatetime":"2015-07-04 20:25:14","UserName":"Mr.Prakash Maheshwari"}]
我想在AngualrJS视图中仅显示$scope.cashsummary = function () {
cashSummaryService.summary($scope.cashSummaryData).then(function (response) {
//$location.path('/property');
$scope.results = response[0].Emailid; alert($scope.results);
}, function (err) {
$scope.message = err.error_description;
});
}; $scope.cashsummary();
,Emailid
,promocode
等字段。当我从控制器调用服务时,我的格式为JSON
答案 0 :(得分:1)
// write this in controller
var data=//take all json data into this variable
var totList=[];
for(var i=0; i<data.length; i++){
var disp={
Emailid:data[i].Emailid,
promocode:data[i].promocode,
usename:data[i]UserName
}
totList.push(disp);
if(i==data.length-1){
$scope.profileList=totList;
}
}
//html for this
<ion-view >
<ion-nav-title> </ion-nav-title>
<ion-content>
<ion-list>
<ion-item ng-repeat="profileList in profileList">
{{profileList.Emailid}}
{{profileList.promocode}}
{{profileList.usename}}
</ion-item>
</ion-list>
</ion-content>
</ion-view>
答案 1 :(得分:0)
虽然这是一个非常基本的例子(它在AngularJS的主页中给出),但这个问题应该关闭,但你可以这样做,如下所示:
angular.module("sa", []).controller('foo', function($scope, $http) {
$scope.cashsummary = function() {
// var url = serviceBase + cashSummaryUrl;
var url = 'http://jsonplaceholder.typicode.com/users';
$http.get(url).success(function(data) {
$scope.results = data;
})
};
$scope.cashsummary();
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="sa" ng-controller="foo">
<div ng-repeat="result in results">
Email ID: {{result.email}}
<br>Code: {{result.website}}<br><br>
</div>
</div>
&#13;