夥計們我有一個模型如下,從Ajax調用返回。AngularJS int映射不工作?
public partial class GroupForm
{
[Key]
public virtual int Id { get; set; }
public virtual int? GroupId { get; set; }
public virtual int? FormId { get; set; }
public virtual int? Frequency { get; set; }
}
在角Ajax調用我GroupForm的列表,然後用NG-重複展現FormID和頻率,而是表示頻率int值,我想顯示字符串,所以我做了映射,但它只顯示GroupId,頻率沒有顯示。 我的控制器部分如下:作爲folloed
FrequencyMap = {
1: "Annual",
2: "Monthly",
3: "Half Year"
}
$scope.mapFrequency = function (col) {
return FrequencyMap[col];
};
而且我前angualrJS代碼:
<ul>
<li ng-repeat="w in GroupForm">
{{ w.FormId+ ', '+mapFrequency(w.Frequency)}}
</li>
</ul>
我使用這個代碼,Ajax調用返回三個GroupForm記錄,它只能顯示3的GroupId,但頻率字符串丟失。但是,如果我使用w.Frequency,它可以顯示int值。 請指點
我如何獲得GroupForm如下:
$scope.GetAllGroupForms = function (Id) {
var url = '/GroupForm/Details/' +Id;
$scope.loading = true;
DataSvc.getAjaxData(url)
.then(function (data) {
//success
$scope.GroupForm = data.data;
$scope.loading = false;
}, function (httpStatus) {
//failed
$scope.hasErrors = true;
if (httpStatus === 404) {
$scope.errorMessage = "Couldn't retrieve Users Info";
} else {
$scope.errorMessage = 'The system could not process your request, please try again or contact the system administrator.';
}
$log.warn(httpStatus);
$scope.loading = false;
});
};
mapFrequency後'缺少一個右括號的方式(w.Frequency' – chiliNUT
是你的ng-repeat實際上工作嗎?你在視圖中獲得3個列表項... – Bowofola
我添加了缺失的閉合parens,但仍然不起作用 –