file objs.json:
{
"id": 1,
"name": "My obj",
"description": "My obj Desc"
}
file my-element.html:
<polymer-element name="my-obj">
<template>
<core-ajax id="ajax" auto url="objs.json"
on-core-response="itemsLoaded" handleAs="json"></core-ajax>
<p>{{obj.name}}</p>
</template>
<script type="text/javascript">
Polymer({
ready: function() {
this.$.ajax.addEventListener("core-response", function(e) {
this.obj= e.detail.response;
});
},
itemsLoaded: function() {
console.log(this.$.ajax);//.response
}
});
</script>
为什么我的{{obj.name}}
没有改变!?!?!
答案 0 :(得分:0)
试试这个
<polymer-element name="my-obj">
<template>
<core-ajax
id="ajax"
url="objs.json"
on-core-response="{{itemsLoaded}}"
handleAs="json"
></core-ajax>
<p>{{obj.name}}</p>
</template>
<script>
Polymer({
ready: function() {
this.$.ajax.go();
},
itemsLoaded: function(e) {
this.obj = e.detail.response;
}
});
</script>
答案 1 :(得分:0)
我找到了我的错误:
<core-ajax id="ajax" auto url="objs.json"
on-core-response="itemsLoaded" handleAs="json"></core-ajax>
应该是:
<core-ajax id="ajax" auto url="objs.json"
on-core-response="{{itemsLoaded}}" handleAs="json"></core-ajax>