错误this.areaTrovata不是函数

时间:2016-02-02 10:12:21

标签: javascript java arrays methods polymer

大家好,非常感谢谁会回答我。 我有这段代码:

<script>
    Polymer({
      is: 'go-catalog-tree',
      properties:{
        items: Array,
        areas: Array,
        prova_area: String,
        prova_name: String,
        end_read_items: {
          type: Boolean,
          value: false
        },
        end_read_areas: {
          type: Boolean,
          value: false
        },
        selectedFolder: {
          type: Object,
          value: {
            name: '',
            area:'',
            children: '',
          },
          notify: true,
        },
      },
        areaTrovata: function(area, child) {
          for(var i=0; i < child.length; i++)
          {
              if(area.compareTo(child.area) == 0)
                 return child[i];
              else 
                 return areaTrovata(area, child);
          }
        },
      loadData: function() {
        this.$.axGetAreas.generateRequest();
        this.$.axGetItems.generateRequest();
      },

      // add a callback to the element's prototype
      ready: function() {
        //document.getElementById('catalogTree')
        //  .addEventListener('folderSelected', this.selectedFolder);

        this.loadData();
      },

      // first argument is the change record for the array change,
      // change.base is the array specified in the binding
      arrayItem: function(change, index, path) {
        // this.get(path, root) returns a value for a path
        // relative to a root object.
        return this.get(path, change.base[index]);
      },




      getItems: function(area){
        var items =[];

        for(var i=0; i < this.items.length; i++){
          if (this.items[i].area === area){
            items.push({
              'name': this.items[i].area + ' ' + this.items[i].item + ' ' + this.items[i].name,
              'open': true,
              'shared': true,
              'id': this.items[i].id,
              'area': this.items[i].area,
              'name': this.items[i].name,
              'matnr': this.items[i].matnr,
              'price': this.items[i].price,
              'currency': this.items[i].currency,
              'item': this.items[i].item,
              'layout': this.items[i].layout,
              'children': [],
            });
          }
        }

        return items;
      },

      getSubAreas: function(areas, area, parent){
          if(area.leaf !== null && area.leaf === 'X'){
           return this.getItems(area.area);

          }else{
                var children = [];

                for(var i=0; i < areas.length; i++){
                if (areas[i].parent === parent){
                    children.push({
                  'name': areas[i].name,
                  'open': true,
                  'depth': areas[i].depth,
                  'shared': false,
                  'children': this.getSubAreas(areas, areas[i], areas[i].area)
                });
              }
            }
                return children;
        }
      },

      handleResponseItems: function() {
        this.items = this.$.axGetItems.lastResponse.items;
        this.end_read_items = true;

        if (this.end_read_areas && this.end_read_items){
          this.displayTree();
        }
      },

      handleResponseAreas: function() {
        this.areas = this.$.axGetAreas.lastResponse.areas;
        this.end_read_areas = true;

        if (this.end_read_areas && this.end_read_items){
          this.displayTree();
        }
      },

      displayTree: function() {
        var list = [];

        for(var i=0; i < this.areas.length; i++){
            if(this.areas[i].parent === undefined ||
            this.areas[i].parent === null ||
            this.areas[i].parent === '')
          {
                list.push({
              'name': this.areas[i].name,
              'open': true,
              'area': this.areas[i].area,
              'depth': this.areas[i].depth,
              'shared': false,
              'children': this.getSubAreas(
                            this.areas,
                            this.areas[i],
                            this.areas[i].area
                          )
            });
            }
        }

        this.areas = [];
        this.items = [];
        this.end_read_areas = false;
        this.end_read_items = false;


        document.querySelector('file-tree').data = {
          'name': 'Catalog',
          'open': true,
          'shared': false,
          'children': list
        };
        document.querySelector('file-tree')
          .addEventListener('folderSelected', this.eventSelectedFolder);
          document.getElementById('mybtn').addEventListener('click', this.eventButtonPressed);
      },

      eventSelectedFolder: function(event){

        this.selectedFolder = {
          'name': event.detail.data.name,
          'area': event.detail.data.area,
          'children': event.detail.data.children,
        };
        this.prova_area = this.selectedFolder.area;
        this.prova_name = this.selectedFolder.name;

        console.log(this.selectedFolder);
        //console.log(this.areaTrovata);
        console.log(this.prova_area);
      },
      addFolder: function(valore_nuovo, area, child){
      var list=[];

      for(var i = 0; i < child.length; i++)
      {
        if(this.area[i].parent === undefined ||
            this.area[i].parent === null ||
            this.area[i].parent === '')
          {
                list.push({
              'name': valore_nuovo,
              'open': true,
              'area': this.areas[i].area,
              'depth': this.areas[i].depth,
              'shared': false,
              'children': this.getSubAreas(
                            this.area,
                            this.area[i],
                            this.area[i].area
                          )
            });
            }
      }
        document.querySelector('file-tree').data = {
          'name': 'Catalog',
          'open': true,
          'shared': false,
          'children': list
        };
        document.querySelector('file-tree')
          .addEventListener('folderSelected', this.eventSelectedFolder);
          document.getElementById().addEventListener('click', this.eventButtonPressed);
      },
       eventButtonPressed: function(e){
         return this.addFolder(document.getElementsByName("gianni"), this.prova_area, 
         this.areaTrovata(this.prova_area,
         document.querySelector('file-tree').data.children));
         console.log(this.addFolder(document.getElementsByName("gianni"), this.prova_area, 
         this.areaTrovata(this.prova_area,
         document.querySelector('file-tree').data.children)));

        },    




   });
  </script>

当我按下按钮时,控制台会返回我:&#34; this.areaTrovata不是一个功能&#34;。 我真的不知道发生了什么,因为自从我这个项目工作一周以来。 再次感谢您的帮助。

0 个答案:

没有答案