[英]How can I display JSON data in angularJS if the key is variable?
我正在為我的學校編寫一個網站,除其他外,它將顯示部門的變化。 這些變化已經通過我編寫的腳本收集了。 為了改善工作流程,我希望將數據自動推送到網站上,因此,當腳本自動將電子郵件發送給部門負責人時,它還將信息另存為JSON數據並將其上傳到服務器,在這里我使用angularJS的$ http.get保存到$ scope中
var integrationFactory = function($http) {
var factory = {};
factory.getNotes = function() {
return $http.get('/ci/json_releasenotes.json');
};
return factory;
};
angular.module('integrationApp').factory('integrationFactory', integrationFactory);
由於發行說明正在不斷升級,因此我將其保存為JSON的唯一方法是,
{"0": "this is the first note", "1": "this is the second note", "2": "etc..." }
但是因為沒有鑰匙,我做不到,
<div ng-repeat key in notes>
{{ key.notes }}
</div>
還有其他方法嗎? 任何幫助將不勝感激。
使用$ index! 做就是了:
<div ng-repeat key in notes>
{{ key[$index] }}
</div>
你可以做這樣的事情
<div ng-repeat ="(key,value) in notes"> {{ value}} </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.