准备好访问动态创建的本地dom

时间:2015-06-29 04:50:45

标签: javascript dom polymer web-component

我正在尝试通过Polymer.dom(this.root).querySelectorAll("#office-cities-acc .city");访问.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>

0 个答案:

没有答案