[英]What is 'this' keyword in .cshtml file and how to use .cshtml code in a .js file
有人可以讓我知道“this”關鍵字在這里做什么以及這個 self.model.get() 方法是什么嗎? 我想將下面的代碼行用於 a.js 文件中的“assc”變量。 我怎樣才能做到這一點?
//var assc = _.find(self.model.get("associations"), { "associationName": data.associationName });
//below is a .cshtml file code snippet
function AssociationsViewModel(associations)
{
var self = this;
var ListPageSize = 5;
var associationInstancesPageSize = 6;
var currentAssociation = null;
}
self.onAddAssociationClicked = function (eventArgs, data)
{
var assc = _.find(self.model.get("associations"), { "associationName": data.associationName });
if (assc)
{
if (assc.isAddNewEnabled)
{
addInstanceToAssociation(self.model, assc);
}
}
}
this keyword is for containing class, here this class is stored in a variable self, and when you are trying to do self.get It is calling get method on containing class of the function.
在 javascript 或 typescript 中,這樣做是為了分離對包含 class 的訪問,有時這可以引用 Z05B8C74CBD96FBF2DE4C1A352Z70
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.