从$http.get JSON调用中删除关键字

Remove keyword from $http.get JSON call

本文关键字:删除 关键字 调用 JSON http get      更新时间:2023-09-26

让我在前面说,我是Angular和JSON调用的初学者。

我正在对JSON对象(?)进行$http.get调用,它看起来像这样:

[{
path: "site:images/gallery/1238.jpg",
data: {
    caption: "",
    url: ""
}
}, {
    path: "site:images/gallery/abelone.jpg",
    data: {
        caption: "",
        url: ""
    }
}, {
    path: "site:images/gallery/carrot.jpg",
    data: {
        caption: "",
        url: ""
    }
}, {
    path: "site:images/gallery/cream.jpg",
    data: {
        caption: "",
        url: ""
    }
}, {
    path: "site:images/gallery/img_2679.jpg",
    data: {
        caption: "",
        url: ""
    }
}, {
    path: "site:images/gallery/img_4908.jpg",
    data: {
        caption: "",
        url: ""
    }
}]

我这样称呼它:

$http.get('/_admin/index.php/rest/api/galleries/get/Restaurant?token=xxx')
.then(function(response) {
    $scope.gallery = response.data;
});

用ng重复:

<article ng-repeat="item in gallery">
    <p>{{item.path}}</p>
</article>

我需要的是以某种方式从每个path"记录"中删除site:关键字。

response.data.path在字符串中与"site:"前缀一起返回,与$http调用无关,因此这只是一个简单的字符串操作。试试这个:

<article ng-repeat="item in gallery">
    <p>{{ item.path.slice(5) }}</p>
</article>