0
我想要做的是做一個下拉選擇從json數據讀取文本。我無法讀取價值,我不知道爲什麼。Angualrjs下拉選擇框閱讀Json對象文本
這裏是我的代碼
我的下拉框:
<label class="item item-input item-select">
<b class="input-label">Claim Type:</b>
<select ng-model="claimType" required>
<option value="Select claim" title="Select Claim" selected disabled>Claim Type</option>
<option ng-repeat="claim in claimType " value="{{claim.value}}"
ng-selected="{{claim.value== claimType}}">
{{claim.text}}
</option>
</select>
</label>
我的JSON對象
angular.module('app')
.factory('WebApi', function() {
var claimType = [{
value: "Car",
text: "Car",
}, {
value: "Boat",
text: "Boat",
}, {
value: "Others",
text: "Others"
}]
})
//Display 50 items randomly
var tempData = [];
for (var i = 0; i < 50; i++) {
var selectedClaimType = claimType[Math.floor((Math.random() * claimType.length))];
tempData.push({
claimType: selectedClaimType.text,
})
};
return {
getClaimTypes: function() {
return selectedClaimType.text;
},
}
在我的控制,我叫
$scope.claimType = WebApi.getClaimTypes();
感謝您的快速反應,如果我有這樣的事情是什麼?我注意到我不能這樣做,因爲我有隨機屬性,你有什麼想法如何解決這個問題?我需要這個for循環,因爲我想顯示50個虛擬數據。謝謝 –
你的代碼顯示你創建了一個'tempData'數組,並向其中推入了一些值,但是我沒有看到你在selectlist綁定中使用那個「隨機」數組的位置...... – Claies
事實上,似乎它正在回報你所期望的;你*想要一個數組,但你實際返回的是一個單一的值。 – Claies