聚合物在我的自定义函数之后注册所有元素
Polymer register all elements after my custom function
我有这个 js 文件
var global_actions ={};
$(document).ready(function () {
myajaxcall(function(response){global_actions=response});
});
我有一个带有模板的元素:
<template>
...
<h1>{{global_actions.greetingtext}}</h1>
...
</template>
问题是在 global_actions=myajaxresponse 之前模板绘制和初始化;
我想要什么
1.Call ajax 并填写 global_actions
2.Draw 个数据绑定到 global_actions 个数据的元素;
我在 myahaxcall(callback);
之前绘制的元素
首先对于 ajax 你可以使用 ajax 组件
https://elements.polymer-project.org/elements/iron-ajax
第二
假设您使用 dom-bind 并且您要放置的自定义元素在主
上
var global_actions ={};
$(document).ready(function () {
myajaxcall(function(response){
//use app or this
app.isFinish = true;
app.response});
});
在html写
<template is="dom-if" if="[[isFinish]]">
<custom-element some-data={{app.greetingtext}}></custom-element>
</template>
因此您的元素仅在您收到来自服务器的响应时呈现。
我有这个 js 文件
var global_actions ={};
$(document).ready(function () {
myajaxcall(function(response){global_actions=response});
});
我有一个带有模板的元素:
<template>
...
<h1>{{global_actions.greetingtext}}</h1>
...
</template>
问题是在 global_actions=myajaxresponse 之前模板绘制和初始化; 我想要什么 1.Call ajax 并填写 global_actions 2.Draw 个数据绑定到 global_actions 个数据的元素; 我在 myahaxcall(callback);
之前绘制的元素首先对于 ajax 你可以使用 ajax 组件 https://elements.polymer-project.org/elements/iron-ajax
第二 假设您使用 dom-bind 并且您要放置的自定义元素在主
上 var global_actions ={};
$(document).ready(function () {
myajaxcall(function(response){
//use app or this
app.isFinish = true;
app.response});
});
在html写
<template is="dom-if" if="[[isFinish]]">
<custom-element some-data={{app.greetingtext}}></custom-element>
</template>
因此您的元素仅在您收到来自服务器的响应时呈现。