這是可能有數據綁定內嵌腳本標記?例如:聚合物1.0數據綁定與行內腳本標記
<script src="{{url}}" class="{{klass}}"></script>
Polymer({
is: "test-app",
ready: function() {
url = "http://google.com/js/some-file.js",
klass = "script-class"
}
});
根據Polymer 1.0 Data Binding docs,我不能拿出更好的東西。
我編輯了這篇文章,以達到我想達到的100%的清晰度。我想用Strip Embedded Checkout:
<form action="" method="POST">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_blahblah"
data-amount="2000"
data-name="Demo Site"
data-description="2 widgets ($20.00)"
data-image="/128x128.png">
</script>
</form>
梅森的回答和安東尼的線索使我這個:
<dom-module id="my-app>
<template>
<form action="" method="POST">
<script
src$="{{url}}" class$="{{klass}}"
data-key$="{{key}}"
data-amount$="{{total}}"
data-name$="{{dname}}"
data-description="2 widgets ($20.00)"
data-image="/128x128.png">
</script>
</form>
</template>
<script>
Polymer({
is: "my-app",
properties: {
selection: {
type: String,
observation: "selectionChanged"
}
},
ready: function() {
this.url = 'https://checkout.stripe.com/checkout.js';
this.klass = 'stripe-button';
this.key = 'pk_test_blahblah';
this.dname = 'Demo';
// this.total = "333"; // this value is not static
},
selectionChanged: function() {
if (true) {
this.total = 50; // I need this to assign to "{{total}}" in the template.
}
};
</script>
</dom-module>
我怎樣才能得到的this.total
價值在script標籤被分配到data-amount
條紋的?
您是否嘗試過在此提及的'$ ='語法:https://www.polymer-project.org/1.0/docs/devguide/data-binding.html#attribute-binding它適用於'class',不適用不過關於腳本標記的確定。另外,你應該使用'this.url ='和'this.klass ='。 – anthony