简体   繁体   English

我不了解js“ $ {method_name}”的某些语法

[英]i don't understand some syntax of js “${method_name}”

Here is the code i didn't understand the some syntax like ${method_name} what we are doing by passing the method name to curly braces. 这是我不理解${method_name}类语法的代码,方法是将方法名称传递给花括号。

  global._jsname.prototype.createEELayer = function (ftRule) {
  if (this.EELayer) { return; }
  var that = this;
  var myStyle = new OpenLayers.Style ({
  externalGraphic : 'images/man.png',
  graphicOpacity : "${opac}",
  cursor : "pointer",
  graphicWidth : "20px",
  label:"${labelNumber}",
  graphicHeight : "20px",
  graphicYOffset : -9,
  graphicXOffset : -12,
  graphicTitle: "Drag me to move along the route"
 },
{ context :{ 
opac : function (feature) { 
  if (feature.editOpacity) {
    return feature.editOpacity;
  } else {
    return "1.0";
  }
}
,labelNumber : function (feature) {
  var labelNo = feature.data.stopN;
  return labelNo;
}
} 
});

this.EELayer = new OpenLayers.Layer.Vector("EELayer",{ 
styleMap: new OpenLayers.StyleMap({
  "default" : myStyle,
  "onSelect":myStyle
}), 
isBaseLayer : false
});
this.mbox.map.addLayer(this.EELayer);
}

One more thing i didn't get is why method name (labelNumbber) is given in ${labelNumber} . 我没有得到的一件事是为什么在${labelNumber}给出了方法名(labelNumbber)。

The expression 表达方式

....
label:"${labelNumber}",

....

is defining a property named label which is assigned a string . 正在定义一个名为label的属性,该属性被分配了一个string So, what the meaning of the term "${labelNumber}" in this string is, is up to the programs further logic. 因此,此字符串中术语“ $ {labelNumber}”的含义是什么,取决于程序的进一步逻辑。

Actually, within these few lines, it has no functionality, as it is only a literal and the property is not used in here. 实际上,在这几行中,它没有功能,因为它只是文字,此处未使用该属性。

This is the usuall way to pass dinamic variable from PHP to html/js {$method_name} . 这是将动态变量从PHP传递到html / js {$method_name}的常用方法。
So this variables/names probably come from other part of your code that reuse the curent file as template. 因此,此变量/名称可能来自代码的其他部分,这些部分将当前文件重新用作模板。

maybe a spring MVC Languange I use it often 也许是我经常使用的春季MVC Languange

http://www.mkyong.com/spring-mvc/spring-mvc-hello-world-example/ http://www.mkyong.com/spring-mvc/spring-mvc-hello-world-example/

seen number 4, it can be used in js also 看到数字4,它也可以在js中使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM