使用$(this)与此相比有什么根本区别
$('.viewComments').click(function(ev){
//returns the desired value
alert(this.getAttribute('id'));
//Gives an error sayin function is not defined
alert($(this).getAttribute('id'));
//returns the desired value
alert($(this).attr('id'));
});
Run Code Online (Sandbox Code Playgroud)
我认为"$(this)"将包含"this"具有的所有功能以及更多..但似乎并非如此.
那么究竟是什么(这个)?和
我在使用它时知道哪些功能可用吗?(我知道我可以通过萤火虫来获取它们.但我想知道是否有其他方式 - 某些文档可能是)
我使用ASP.net Identity创建了一个承载令牌.在AngularJS中,我编写了这个函数来获取授权数据.
$scope.GetAuthorizeData = function () {
$http({
method: 'GET',
url: "/api/Values",
headers: { 'authorization': 'bearer <myTokenId>' },
}).success(function (data) {
alert("Authorized :D");
$scope.values = data;
}).error(function () {
alert("Failed :(");
});
};
Run Code Online (Sandbox Code Playgroud)
所以我想将此令牌存储到浏览器cookie中.如果此处存在此令牌,则获取令牌并从IIS服务器获取数据,否则重定向到登录页面以登录以获取新令牌.
同样,如果用户点击退出按钮,它应该从浏览器cookie中删除令牌.
这该怎么做 ?有可能吗?是验证和授权用户的正确方法吗?如果有多个用户令牌怎么办?
路由条件:
1) path: /login , component: LoginComponent
2) path: /inbox , component: InboxMessageComponent
3) path:/inbox/all , "Load InboxMessageListComponent in Right side Box Only",
4) path:/inbox/13 , "Load InboxMessageDetailComponent in Right side Box Only"
Run Code Online (Sandbox Code Playgroud)
所以我创建了两个名为app-routing.module.ts和inbox-routing.module.ts的路由模块.
APP-routing.module.ts
@NgModule({
imports: [
RouterModule.forRoot([
{ path: 'login', component: LoginComponent},
{ path: 'inbox', component: InboxMessageComponent },
{ path: '', component: InboxMessageComponent },
{ path: '**', component: NotFoundComponent }
])
],
exports: [RouterModule]
})
Run Code Online (Sandbox Code Playgroud)
收件箱 - routing.module.ts
@NgModule({
imports: [
RouterModule.forChild([
{path: '/inbox/list',component: InboxMessageListComponent},
{path: '/inbox/detail/:id',component: …Run Code Online (Sandbox Code Playgroud) 我有两张桌子:
Id,Name,DepartmentIdId,NameEmployee.cs:
public int Id {get;set;}
public string Name {get;set;}
public int DepartmentId {get;set;}
Run Code Online (Sandbox Code Playgroud)
Department.cs:
public int Id {get;set;}
public string Name {get;set;}
Run Code Online (Sandbox Code Playgroud)
ViewModel:EmployeeDepartmentVM:
public Department department {get;set;}
public List<Employee> employees {get;set;}
Run Code Online (Sandbox Code Playgroud)
要加入这两个表我写了这段代码:
SELECT E.* , D.Id as DId , D.Name as DName
from [Employee] as E
LEFT OUTER JOIN [Department] as D
ON E.DepartmentId = D.Id
where D.Id = 1
Run Code Online (Sandbox Code Playgroud)
如何从上面的查询中获取EmployeeDepartmentVM类型?
我知道如果我写一个像我的问题的模型将被解决:
public int Id {get;set;}
public string Name …Run Code Online (Sandbox Code Playgroud) 我需要从ID 列表中删除多个ID.
public IHttpActionResult Delete(List<string> IDs)
{
DealBazarEntities.Restaurants.RemoveRange(IDs);
DealBazarEntities.SaveChanges();
}
Run Code Online (Sandbox Code Playgroud)
但是RemoveRange不允许多个ID,它只是期望List<entities>.
是的,我知道,如果我将实体列表发送到服务器而不是发送ID列表,那么我可以很容易地实现这一点.但我不喜欢那样.
同样,我不想使用foreach循环遍历每个ID.
我有一个JavaScript对象.
var obj = { Id: "100", Name: "John", Address: {Id:1,Name:"Bangalore"} }
var dataToRetrieve= "Name";
function GetPropertyValue(object,dataToRetrieve){
return obj[dataToRetrieve]
}
var retval = GetPropertyValue(obj,dataToRetrieve)
Run Code Online (Sandbox Code Playgroud)
这很好用.但是,如果我尝试获取"Address.Name"的属性值的值,
喜欢:var dataToRetrieve = "Address.Name";
它表明undefined.
注意:属性变量由用户从HTML设置并且可以根据用户要求(他想要的属性值)进行更改.
我想要实现的目标:
1)如果dataToRetrieve = "Name",它应该给我"John",
2)如果dataToRetrieve = "Id",它应该给我"100",
3)如果dataToRetrieve = "Address.Name",它应该给我"Bangalore",
4)如果dataToRetrieve = "Address.Id",它应该给我1
Plunkr在这里:PLUNKR
当我执行以下查询时,我得到输出,但是当我传递NULL参数时,它不起作用.
例1:
DECLARE
@a int = NULL,
@b int = NULL,
@c int = NULL
SELECT COALESCE(@a, @b,@c)
GO
Run Code Online (Sandbox Code Playgroud)
输出:NULL
例2:
SELECT COALESCE(NULL, NULL,NULL)
GO
Run Code Online (Sandbox Code Playgroud)
输出:COALESCE的至少一个参数必须是不是NULL常量的表达式.
有人可以解释,为什么示例1正在工作,但示例2没有.
c# ×2
javascript ×2
jquery ×2
sql ×2
sql-server ×2
ado.net ×1
angular ×1
angularjs ×1
arrays ×1
asp.net-mvc ×1
dom-events ×1
this ×1