这是我的代码
var studentsList = [
{"Id": "101", "name": "siva"},
{"Id": "101", "name": "siva"},
{"Id": "102", "name": "hari"},
{"Id": "103", "name": "rajesh"},
{"Id": "103", "name": "rajesh"},
{"Id": "104", "name": "ramesh"},
];
function arrUnique(arr) {
var cleaned = [];
studentsList.forEach(function(itm) {
var unique = true;
cleaned.forEach(function(itm2) {
if (_.isEqual(itm, itm2)) unique = false;
});
if (unique) cleaned.push(itm);
});
return cleaned;
}
var uniqueStandards = arrUnique(studentsList);
document.body.innerHTML = '<pre>' + JSON.stringify(uniqueStandards, null, 4) + '</pre>';Run Code Online (Sandbox Code Playgroud)
产量
[
{
"Id": "101",
"name": "siva"
}, …Run Code Online (Sandbox Code Playgroud) 这是我的代码
$http.get("/Student/GetStudentById?studentId=" + $scope.studentId + "&collegeId=" + $scope.collegeId)
.then(function (result) {
});
Run Code Online (Sandbox Code Playgroud)
在上面的代码中使用http服务来获取基于id的学生详细信息.但是我想在c#.net中编写上面的服务string.format
(eg:- string.format("/Student/GetStudentById/{0}/collegeId/{1}",studentId,collegeId)
Run Code Online (Sandbox Code Playgroud) 这是我的代码
var app = angular.module('app', ['ngTouch', 'ui.grid', 'ui.grid.pagination']);
app.controller('MainCtrl', [
'$scope', '$http', 'uiGridConstants', function($scope, $http, uiGridConstants) {
var paginationOptions = {
pageNumber: 1,
pageSize: 25,
sort: null
};
$scope.gridOptions = {
paginationPageSizes: [25, 50, 75],
paginationPageSize: 25,
useExternalPagination: true,
useExternalSorting: true,
columnDefs: [
{ name: 'name' },
{ name: 'gender', enableSorting: false },
{ name: 'company', enableSorting: false }
],
onRegisterApi: function(gridApi) {
$scope.gridApi = gridApi;
$scope.gridApi.core.on.sortChanged($scope, function(grid, sortColumns) {
if (sortColumns.length == 0) {
paginationOptions.sort = null;
} else …Run Code Online (Sandbox Code Playgroud)我想在用户关闭浏览器或使用angularjs中的窗口选项卡时清除本地存储值.我尝试了以下代码.
window.addEventListener("beforeunload", function (e) {
var confirmationMessage = "\o/";
alert("exit");
(e || window.event).returnValue = confirmationMessage; //Gecko + IE
return confirmationMessage; //Webkit, Safari, Chrome
});
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,它会在刷新页面时关闭确认警报消息并关闭页面.但是我想在关闭浏览器/ Window选项卡时激活angularjs事件,而不需要询问确认消息.
这是我的代码
public ActionResult Contact()
{
//var getRequest = (HttpWebRequest)WebRequest.Create("https://brisol.net/av-d");
//var getResponse = (HttpWebResponse)getRequest.GetResponse();
//return new HttpWebResponseResult(getResponse);
return ExternalGet("https://sample.net/av-d");
}
/// <summary>
/// Makes a GET request to a URL and returns the relayed result.
/// </summary>
private HttpWebResponseResult ExternalGet(string url)
{
var getRequest = (HttpWebRequest)WebRequest.Create(url);
var getResponse = (HttpWebResponse)getRequest.GetResponse();
return new HttpWebResponseResult(getResponse);
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,当我单击联系链接时,它会在同一窗口中打开以下网址,但我想从 mvc 控制器打开新窗口。
array1 = ["one","two"];
array2 = [ {"name":"one","id":101} , {"name":"two","id":102} , {"name":"three","id":103} , {"name":"four","id":104} ];Run Code Online (Sandbox Code Playgroud)
在上面的数据中,array1是一个字符串值array2的集合,是一个对象的集合.现在如何删除array1相关的值array2.我使用for循环编写代码但是它太长了所以angular-6/typescript中存在任何预定义的方法.
输出:
array2 = [ {"name":"three","id":103} , {"name":"four","id":104} ];
Run Code Online (Sandbox Code Playgroud) 我有存储员工 ID 的本地存储。当我刷新浏览器时,根据员工 ID 获取本地存储值,如员工 ID 获取一些数据。当我关闭浏览器时,我想使用 angularjs 或 javascript 清除本地存储中的员工 ID。我尝试了以下代码。
window.onunload = close;
function close() {
//// do something...
localStorage.clear();
return null;
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,当我刷新浏览器时,window.onunload 也会触发并清除本地存储值,但我只想在浏览器关闭时清除本地存储。
我有一个带有数组数据的字符串变量。
var str = "[\r\n 10,\r\n 20\r\n]" ;
Run Code Online (Sandbox Code Playgroud)
我想像使用javascript一样将上述字符串转换为数组。
输出:-
var arr = [10,20];
Run Code Online (Sandbox Code Playgroud)