
1:调用Custom Label (只有在.app .com才可以使用)
Label.c.labelName 默认的名前空间
Label.namespace.labelName 自己的名前空间
2:使用Format例如:{!format($Label.np.labelName, v.name)}如果你有一个customLabal
名字是np.labelName,被设置成Hello {0},另外还有一个本地name变量被设置成World
那么,最终上边儿的表达式将被设置成Hello World.
注意只能用CustomLabel 而不能用String。{!format('Hello {0}', v.name)}
3:通过JavaScript获取Label
静态:
var staticLabel = $A.get("$Label.c.task_mode_today");
component.set("v.mylabel", staticLabel);
动态:
// Assume the day variable is dynamically generated
// earlier in the code
// THIS CODE WON’T WORK
var dynamicLabel = $A.get("$Label.c." + day);
Label应用
var labelSubStr = "task_mode_today";
var labelReference = $A.getReference("$Label.c." + labelSubStr);
cmp.set("v.tempLabelAttr", labelReference);
var dynamicLabel = cmp.get("v.tempLabelAttr");
声明引用并且关联Label,把引用设置到Component的属性上,然后在Javascript里就可以获取属性并且使用了。
使用Apex获取Label
public with sharing class LabelController {
@AuraEnabled
public static String getLabel() {
String s1 = 'Hello from Apex Controller, ' ;
String s2 = System.Label.MyLabelName;
return s1 + s2;
}
}

567

被折叠的 条评论
为什么被折叠?



