Javascript 在就绪时访问动态创建的本地dom

Javascript 在就绪时访问动态创建的本地dom,javascript,dom,polymer,web-component,Javascript,Dom,Polymer,Web Component,我正试图通过Polymer.dom(this.root).queryselectoral(#office cities acc.city)访问ready上的.city元素但它没有返回任何内容。我认为这是因为这些元素是通过dom repeat动态创建的。是这样吗?访问它们的方式是什么 <template> <iron-ajax auto url="@{Office.getOffices}" params='{"alt":"json", "q

我正试图通过
Polymer.dom(this.root).queryselectoral(#office cities acc.city)访问ready上的.city元素但它没有返回任何内容。我认为这是因为这些元素是通过dom repeat动态创建的。是这样吗?访问它们的方式是什么

    <template> 
       <iron-ajax
        auto url="@{Office.getOffices}" params='{"alt":"json", "q":"polymer"}'
        handle-as="json" last-response="{{ajaxResponse}}"></iron-ajax>

    ....
            <div class="office-cities-list">
                <div class="panel-group" id="office-cities-acc">
                    <template is="dom-repeat" items="[[ajaxResponse.officesRegions]]"
                        as="region">
                            <template is="dom-if" if= "{{checkRegionType(region.type)}}">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                             ...
                        </div>
                        <div id="{{computeUrl(region.regionsId)}}"
                            class="panel-collapse collapse">
                            <div class="panel-body">
                                <ul>
                                    <template is="dom-repeat" items="[[ajaxResponse.officesCities]]"
                                        as="city">
                                        <template is = "dom-if" if="{{checkCityRegion(region.regionsId,city.regionsId)}}">
                                    <li class="city"><a href="#" 
                                        data-city-name$={{getNameByLang(city)}}>{{getNameByLang(city)}}</a></li>
                                    </template></template>....

</template>

....
...
  • ....
您希望实现什么目标?我猜您是在根据ajax调用的响应构建城市列表。在
ready
回调中无法执行此操作,因为创建自定义元素时会调用
ready
回调。您可以为
ajaxResponse
属性添加一个
observer
,并尝试在那里访问它们。您想尝试实现什么?我猜您是在根据ajax调用的响应构建城市列表。在
ready
回调中无法执行此操作,因为创建自定义元素时会调用
ready
回调。您可以为
ajaxResponse
属性添加一个
observer
,并尝试在那里访问它们。