在Polymer中动态地将新元素添加到自定义元素中

时间:2015-07-12 09:44:41

标签: javascript polymer-1.0

我正在编写一个聚合物应用程序,服务器将根据请求返回图像文件名。 1或2个图像文件可能会返回。我想在阴影dom中添加动态生成的铁图像元素。我可以检查是否添加了铁图像元素,但图像没有显示。什么错了?
" test3.png"与html文件位于同一位置。

public class MyRunnable implements Runnable{

    @Override
    public void run() {

        System.out.println("Thread 1 :First Thread started");
    }

    public static Runnable delay(){
        Runnable r = new Runnable(){

            @Override
            public void run() {  // running state

                System.out.println("Thread 2: loading second thread..");
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("Thread 2: System loaded");
            }

        }; // finished state
        return r;
    }

    public static Runnable waiting(){
        Runnable r = new Runnable(){

            @Override
            public void run() { // running state

                System.out.println("Thread 3: waiting..");
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("Thread 3: OK");

            }

        }; // finished state
        return r;
    }


    public static void main(String[] args) throws InterruptedException{

       Thread thread1 = new Thread(new MyRunnable());      
       Thread thread2 = new Thread(delay()); 
       Thread thread3 = new Thread(waiting()); // (initial state)

       thread1.start();
       thread2.start();
       thread3.start();

    }


}

1 个答案:

答案 0 :(得分:0)

使用img.src,这样就可以访问绑定的组件属性而不是html元素属性。

这是你的示例有点扩展,也将src属性暴露给元素之外的世界:https://gist.github.com/IgorRubinovich/36bc1ce3a314ed7cf032

有关详情,请参阅http://www.polymer-project.org/1.0/docs/devguide/properties.html