admin管理员组文章数量:1417682
How can we concatenate an expression value with some string and evaluate the resulting expression?
If we have one object prefix and I wanted to concatenate its value with some string. e.g
{{prefix"Output"}}
I would like to first evaluate the prefix value and then concatenate it with the "Output" string.
So the resulting expression may be something like "UnitOutput" where Unit is the value of the prefix.
Lastly I want the concatenated expression from above to be evaluated as well in that case resulting value will be the value of "UnitOutput".
How can we concatenate an expression value with some string and evaluate the resulting expression?
If we have one object prefix and I wanted to concatenate its value with some string. e.g
{{prefix"Output"}}
I would like to first evaluate the prefix value and then concatenate it with the "Output" string.
So the resulting expression may be something like "UnitOutput" where Unit is the value of the prefix.
Lastly I want the concatenated expression from above to be evaluated as well in that case resulting value will be the value of "UnitOutput".
Share Improve this question asked Apr 24, 2015 at 8:03 RazaRaza 3101 gold badge4 silver badges11 bronze badges 1- I actually want to achieve something like this {{ {{prefix}}"Output" }} – Raza Commented Apr 24, 2015 at 11:12
4 Answers
Reset to default 1The keyword prefix
did not work for me. I am assuming it is a reserved keyword. I will use pref
in this example.
Html
<paper-input value="{{pref}}"></paper-input>
<span>Output: {{result}}</span>
Javascript
Polymer({
pref: '',
result: 'Output',
prefChanged: function(oldValue, newValue) {
this.result = newValue + 'Output';
// evaluate result here
}
}
Or you could use Polymers observer pattern
Html
<paper-input value="{{xyz.prefix}}"></paper-input>
<span>Output: {{result}}</span>
Javascript
Polymer({
result: '',
observe: {
'xyz.prefix': 'validate'
},
validate: function(oldValue, newValue) {
this.result = newValue + 'Output';
},
ready: function() {
this.xyz = {
prefix: 'test'
}
}
});
If you're observing Arrays please refer to observe-js
doing like
"{{variable}} Output"
should work
With RactiveJS it's simply:
{{ this[prefix + "Output"] }}
See http://jsfiddle/236bsky0/. this
refers to current context or root, but can be another reference if you like.
You can also use a function : {{ getValue(variable) }} In your element, just declare your function : getValue: function(var) { return var + "Output";}
本文标签: javascriptMustache template concatenation of expression with some stringStack Overflow
版权声明:本文标题:javascript - Mustache template concatenation of expression with some string - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745269889a2650824.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论