我正在尝试填充 angularjs 中的下拉按钮。
我收到以下错误。 “表达式意外结束:data.WotcSummary”|
我做错了什么。
js文件:
WotcDashBoardModule.controller('WotcDashBoardController', ['$scope', 'WotcDashBoardModuleService', function ($scope, WotcDashBoardModuleService) {
var Ein = '95-000000';
WotcDashBoardModuleService.GetDashBoardSummary(Ein).then(function (response) {
$scope.Summary = response.data.WotcSummary;
//console.log($scope.Summary.Locations);
});
}]);
Locations 是一个包含两个项目的数组
[Object, Object, Object]
0:Object
corporateId:1600
location:"California"
__proto__:Object
1:Object
corporateId:1600
location:"Atlanta"
__proto__:Object
2:Object
corporateId:1600
地点:“波士顿”
HTML:
<div class="btn-group btn-toolbar btn-margin-left" style="float: right;" >
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
ALL LOCATIONS
<span class="caret"></span>
</button>
<div class="dropdown-menu">
<select name="ListLocations" class="form-control input-md"
ng-model="Locations"
ng-options="Locations.location for Locations in data.WotcSummary | track by Locations.location">
<option value=""> </option>
</select>
</div>
</div>
返回到 View 的业务对象类是:
public class CompanyWotcBO
{
public int Id { get; set; }
public int IdUser { get; set; }
public int IdCandidate { get; set; }
public int DocsSubmitted { get; set; }
public int DocsRecieved { get; set; }
public string CompanyId { get; set; }
public string EIN { get; set; }
public string Error { get; set; }
public List<Location> Locations { get; set; }
public CompanyWotcBO()
{
Locations = new List<Location>();
}
}
public class Location
{
public int corporateId { get; set; }
public string location { get; set; }
}
这是返回的完整 json 对象::
Object {Id: 0, IdUser: 0, IdCandidate: 0, NewEmployees: 458, WotcScreened: 458…}
CompanyId:null
DocsRecieved:0
DocsSubmitted:0
EIN:null
Error:null
Id:0
IdCandidate:0
IdUser:0
Locations:Array[3]
0:Object
corporateId:1600
location:"95-3874566"
__proto__:Object
1:Object
corporateId:1600
location:"Atlanta"
__proto__:Object
2:Object
corporateId:1600
location:"Boston"
__proto__:Object
3:Object
corporateId:1600
location:"Chicago"
__proto__:Object
最佳答案
ng-options 中不需要 '|'
<select name="ListLocations" class="form-control input-md"
ng-model="Locations"
ng-options="Locations.location for Locations in data.WotcSummary track by Locations.location">
<option value=""> </option>
关于javascript - 从 json 对象填充下拉列表时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37598132/