Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Polymer 如何将项目动态添加到聚合纸张树?_Polymer - Fatal编程技术网

Polymer 如何将项目动态添加到聚合纸张树?

Polymer 如何将项目动态添加到聚合纸张树?,polymer,Polymer,我在代码中使用了polymer paper树元素。它完美地用静态数据显示了树,但是当我尝试动态添加项目时,它不起作用。我在这里附上一个截图 //排列 this.itemArray = {"name": "Project", "icon": "theaters", "open": true,

我在代码中使用了polymer paper树元素。它完美地用静态数据显示了树,但是当我尝试动态添加项目时,它不起作用。我在这里附上一个截图

//排列

    this.itemArray = {"name": "Project",
                                                "icon": "theaters",
                                                "open": true,
                                                "children": [{
                                                    "name": "Quotes",
                                                    "icon": "theaters",
                                                     "open": true,
                                                    "children": [{
                                                      "name": "Breaking Bad",
                                                        "icon": "theaters"
                                                    }]
                                                }, {
                                                    "name": "Templates",
                                                    "icon": "theaters",
                                                     "open": true,
                                                    "children": [{
                                                        "name": "Breaking Bad",
                                                        "icon": "theaters"
                                                    }, {
                                                        "name": "Game of Thrones",
                                                        "icon": "theaters"
                                                    }]
                                                }]
                                      }

   //Js code which accepts value from a text box and adds it to the array.


 this.$.additem.addEventListener("click", function(){

enter code herevar data = self.$.txtData.value;
                                                                           self.itemArray.children[1].children.push(
                                          {'name':data,
                                           'icon':'theaters'});

                                          self.addData(self.itemArray,data);
                                          self.$.txtData.value = " ";


                                  });

// addData function



addData:function(itemsarr){
                      console.log("calling items array function",this.tree);
                      var tempArr = [];
                      tempArr = itemsarr;
                      if(this.tree){
                       this.$.temp.removeChild(this.tree);
                       //tempArr = itemsarr; //= this.itemArray2;
                      }

                      this.tree = document.createElement('paper-tree-node');
                      this.tree.setAttribute('id','treemenu');
                      this.$.temp.appendChild(this.tree);
                      this.tree.data = tempArr;
                      console.log(tempArr);

      }

聚合物纸树具有数据属性。你只需要更新它


帮助链接:

您尝试过聚合物阵列功能吗?是 啊数组被证明是正确的,但它并没有正确地应用到树上。只有第一个动态项正确添加了文本和图标,但之后它只显示文件夹图标。不确定是什么问题。能否编辑问题并添加一些代码?所以我们可以看看你有什么。。我已经编辑了代码。。请检查我不知道你的代码里发生了什么。当您想将数据推送到树中时,是否要删除并重新创建整个元素?那是错误的。您应该为此使用绑定。示例:
然后在脚本中
this.push(“数据”,“某些对象…”)
但我不确定这是否解决了您的问题。我真的不太懂那个代码。也许有人谁知道纸树更多可以帮助