在我的 javascript 文件中,我想使用类似语句的 linq 查询来显示我的结果。以下是我的视图模型和有关我如何获取信息的信息。
var viewModel = {
RosterRoleTypes: ko.observableArray([])
};
// the ViewModel for the array of RoleTypes
var roleTypesViewModel = function (data) {
roleTypesViewModel.AddRoles(data);
}
// Adds multiple roles to the array of RoleTypes
roleTypesViewModel.AddRoles = function (data) {
$.each(data, function (index, value) {
roleTypesViewModel.PushRole(value);
});
};
//Add a single role to the array of Roles
roleTypesViewModel.PushRole = function (role) {
viewModel.RosterRoleTypes.push(new roleViewModel(role));
}
// the ViewModel for a single Role
var roleViewModel = function (data) {
var _self = this;
_self.ContentRole = ko.observable(data.ContentRole);
_self.RoleName = ko.observable(data.RoleName);
_self.RoleRank = ko.observable(data.RoleRank);
_self.UserCount = ko.observable(data.UserCount);
};
在我OnSuccess
的 get 方法中,我想做如下的事情:
var results = Enumerable.From(viewModel)
.ForEach(RoleTypes){ show RoleName and UserCount}
我怎样才能正确地使用 Enumerable.From 编写该语句...