Fuel UX树的递归问题

时间:2013-09-22 05:56:18

标签: java jsp tree fuelux

我有这段代码:

    <script>
              $(window).load(function() {

         var DataSource = function (options) {
this._formatter = options.formatter;
this._columns = options.columns;
this._data = options.data;
};

DataSource.prototype = {

columns: function () {
    return this._columns;
},

data: function (options, callback) {

    var self = this;
    if (options.search) {
        callback({ data: self._data, start: start, end: end, count: count, pages: pages, page: page });
    } else if (options.data) {
        callback({ data: options.data, start: 0, end: 0, count: 0, pages: 0, page: 0 });
    } else {
        callback({ data: self._data, start: 0, end: 0, count: 0, pages: 0, page: 0 });
    }
}
};


var treeDataSource = new DataSource({
  data: [
    { name: 'Folder 1', type: 'folder', additionalParameters: { id: 'F1' },
      data: [
        { name: 'Sub Folder 1', type: 'folder', additionalParameters: { id: 'FF1' } },
        { name: 'Sub Folder 2', data: [
          {name: 'sub sub folder 1', type: 'folder', additionalParameters: { id: 'FF21' }},
            {name: 'sub sub item', type: 'item', additionalParameters: { id: 'FI2' }}
            ], type: 'folder', additionalParameters: { id: 'FF2' }},
        { name: 'Item 2 in Folder 1', type: 'item', additionalParameters: { id: 'FI2' }    }
        ]
    },
    { name: 'Folder 2', type: 'folder', additionalParameters: { id: 'F2' } },
    { name: 'Item 1', type: 'item', additionalParameters: { id: 'I1' } },
    { name: 'Item 2', type: 'item', additionalParameters: { id: 'I2' } }
  ],
        delay: 400
    });

    $('#MyTree').tree({dataSource: treeDataSource});

    $('#tree-selected-items').on('click', function () {
        console.log("selected items: ", $('#MyTree').tree('selectedItems'));
    });

    $('#MyTree').on('loaded', function (evt, data) {
        console.log('tree content loaded');
    });

    $('#MyTree').on('opened', function (evt, data) {
        console.log('sub-folder opened: ', data);
    });

    $('#MyTree').on('closed', function (evt, data) {
        console.log('sub-folder closed: ', data);
    });

    $('#MyTree').on('selected', function (evt, data) {
        console.log('item selected: ', data);
    });

              });
                </script>

我正在使用http://exacttarget.github.io/fuelux/#tree 问题是,当我打开一个文件夹时,它会保持包含其他文件夹,如示例中所示。喜欢它永远不会结束。怎么能避免这种情况?

感谢。


修改

我这样做了它的工作......你觉得它没问题吗?

var cont = 0;
DataSource.prototype = {

columns: function () {
return this._columns;
},

data: function (options, callback) {

var self = this;
if (options.search) {
    callback({ data: 0 , start: 0, end: 0, count: 0, pages: 0, page: 0 });
} else if (options.data) {
    callback({ data: options.data, start: 0, end: 0, count: 0, pages: 0, page: 0 });
} else if (cont == 0) {
    callback({ data: self._data, start: 0, end: 0, count: 0, pages: 0, page: 0 });
}
        else {
            callback({ data: 0, start: 0, end: 0, count: 0, pages: 0, page: 0 });
        }
         cont = cont+1;
}

};

使用cont i第一次回调数据(加载树时)。之后它只返回0.

1 个答案:

答案 0 :(得分:0)

以下是一个简单示例:http://www.bootply.com/64521

感谢@Skelly解决方法的细节。