为什么变量替换只推荐用于在小部件的生命周期内不会改变的值?

Why is variable substitution only recommended for values that wont change during lifetime of a widget?

关于 Dojo 中的变量替换

Variable Substitution: A template can have values set on DOM rendering though the use of a simple variable placeholder syntax, which looks like this:

${property}

根据文档

Variable substitution in a template is only recommended for values that will not be changed during the lifetime of the widget. In other words, if you expect to be able to set the value of a property in a widget during the lifetime of your application programmatically, we recommend instead using your widget's postCreate method to set any variables programmatically through your widget's set() method.

谁能解释一下为什么提出这个建议?

Dojo 中的变量替换没有绑定。 这意味着即使您更改变量的实际值它也不会改变。

如果需要绑定,则可以使用附加点和 setter 作为该值。然后它将具有绑定,并且 UI 将更新为新值。 像这样:

    _setLabelAttr : {
        node : "_tplLabelNode",
        type : "innerHTML"
    },

会将附加点 _tplLabelNodeinnerHTML 绑定到小部件的 "label" 属性。
所以 widget.set('label', 'foo'); 将更新 UI。

但是<div>${label}</div>没有绑定。 ${label} 将在创建小部件时被替换并且永远不会更新