在下面的精簡代碼示例中,core-localstorage元素不應該將全局js變量`itemsApiURL'的值加載到{{value}}中,以便在自定義元素準備好時將其傳遞到my-datasource-element中?或者,core-localstorage的目的僅限於將值寫入localstorage?目前,儘管my-datasource-element的ready()事件存在全局變量(理想情況下設置爲外部js配置文件,不包含在頭部,如下所示),但{{value}}未定義。我絕對沒有做正確的事情......也許我對js缺乏安慰,或者某種事件發生的範圍/順序問題。聚合物core-localstorage - 加載預先存在的全局js變量
也許有一個完全更好的方法來配置聚合物應用程序範圍的變量/常量,以便值可以很容易地用於我的所有應用程序元素,或者至少通過雙向數據綁定作爲元素屬性傳遞?這真的是我認爲的更重要的問題......但無論如何,我仍然對核心本地存儲如何運作感到困惑。
<html>
<head>
<script>
this.itemsApiURL = "http://server:port/api/items";
</script>
<link rel="import" href="./components/platform/platform.js">
<link rel="import" href="./components/core-localstorage/core-localstorage.html">
</head>
<body fullbleed unresolved>
<template is="auto-binding">
<core-localstorage name="itemsApiURL" value="{{value}}"></core-localstorage>
<my-datasource-element url="{{value}}" items="{{items}}"><my-datasource-element>
</template>
</body>
</html>
同意。更直接的實現。感謝您的補充說明。 – sinjins 2014-09-15 17:54:56