【问题标题】:Get json data into ioni view将json数据获取到ioni视图中
【发布时间】:2016-12-24 15:04:22
【问题描述】:

我有这个控制器...

"use strict";

var app = angular.module('ng-laravel');
app.controller('StartCtrl',function($scope, $http,$rootScope,$ionicLoading,$cordovaDevice,$cordovaVibration,ionicToast,$ionicPlatform,$cordovaNetwork){
    $http.get('https://www.myurl.com/stringjson').
    success(function(data, status, headers, config) {
        $scope.progetti = data.items;
    }).
    error(function(data, status, headers, config) {
    // log error
    });
});

正确地获取这样的 json 数据:

    [{"id":2,"titolo":"The Marriage","descrizione":"Sal, a thirteen year old girl, narrates a story told
 by her Grandfather, which begins in a hospital room after Sal\u2019s Grandmother becomes ill during
 a road trip.  The story of The Marriage Bed flashes back to small-town Kentucky, where Sal\u2019s grandparents
 first met.  Gramps feels love at first sight for Gram, and courts her for the better part of a month
 before she accepts a marriage proposal.  On the night of their wedding, Gramps and Gram find a special
 bed in their new home: the bed that had belonged to Gramps\u2019 parents, and the bed that they\u2019ve
 slept in all of their lives since.  The tale ends with Sal wondering about her own romantic future.
  ","inizio":"2016-12-17 00:00:00","fine":2016,"goal":10000,"banner":"1457196511-29619972.png","entry_by"
:1,"created_at":"2016-03-05 17:48:31","updated_at":"2016-03-06 11:33:02","funded":"0","pledged":1000
,"image":"","id_categoria":5,"staff_picked":null,"vetrina":null,"summary":"A young girl traveling with
 her Grandparents recounts a favorite family love story ","numero_finanziatori":2,"active":1,"tags":""
,"banner3":"","image2":"","image3":"","motivazione":"Vediamo se funziona","didascalia":"Prova prova"
,"rating":5,"prima":0,"id_azienda":0,"banner2":""}

这是我的观点,我无法显示数据...

    <div class="hero no-header flat">
        <div class="content">
            <div class="app-icon"></div>
            <h2 class="light">Welcome</h2>
            <p class="stable">Our projects</p>
        </div>
    </div>
    <ion-list>
            <ion-item ng-controller="StartCtrl" class="item-avatar">
                <h2>{{ items[0].nome}}</h2>
            </ion-item>
        </ion-list>
    <div class="padding">
        <button type="submit" class="button button-full button-assertive ink">{{ data.nome }}</button>
        <button ui-sref="login" class="button button-full button-clear button-light">back to login</button>

    </div>
</ion-content>

【问题讨论】:

    标签: angularjs json ionic-framework


    【解决方案1】:

    您正在打印错误的变量..

    <ion-list>
                <ion-item ng-controller="StartCtrl" class="item-avatar">
                    <h2>{{ progetti[0].titolo}}</h2>
                </ion-item>
            </ion-list> 
    

    试试这个.. 只有 $scopethis 变量是自动同步的。

    【讨论】:

    • 对不起,错误的变量:) 它不是名字而是标题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-24
    • 2018-12-16
    • 1970-01-01
    • 2016-05-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多