我已经编写了一个函数(Polymer 1.2.0)来返回iron-ajax的auth头,但无论我尝试什么,我都会收到消息
not defined
{makeheaders {1}}
除了这段代码之外,我还尝试了`Polymer({is:'dom-bind'} ... blah:fn()'绑定fn的方式。
我做错了什么?这是代码的相关部分:
<div id="futuretweets" style="height: 400px">
<template is="dom-bind" id="big-temp">
<script>
document.querySelector('template[is=dom-bind]').makeheaders = function () {
var obj = {};
obj.Authorization = "Bearer " + localStorage.getItem('userToken');
return obj;
};
</script>
<iron-localstorage name="auth" value="{{localtoken}}"></iron-localstorage>
<iron-ajax url="api/twitter/v1/private/gettweets" last-response="{{data}}" auto
headers="{{makeheaders()}}"
handle-as="json">
</iron-ajax>
<iron-list items="[[data.futuretweets]]" as="item">
<template id="tweet-item">
<form is="iron-form" id="tweetform" method="post" action="api/twitter/v1/private/updatetweet"
headers="{{makeheaders()}}" contentType="application/json">
<div class="card layout horizontal center">
<paper-textarea label="Tweet">[[item.text]]</paper-textarea>
<p>datetime: [[item.datetime]]</p>
</div>
<paper-button>Save</paper-button>
</form>
</template>
</iron-list>
</template>
<div id="tweeteditor">
</div>
</div>
答案 0 :(得分:1)
将脚本移到template
元素之外。模板是静态的。您的代码中发生的事情是,在将dom-bind
标记为标记后,您将声明class Exception
{
public static void main(String args[])
{
int x = 10;
int y = 0;
int result;
try{
result = x / y;
}
catch(ArithmeticException e){
System.out.println("Throwing the exception");
throw new ArithmeticException();
}
}
}
的属性。