Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #817 from swilliamset/Issue-#784---Tree--Data-Sour…
Browse files Browse the repository at this point in the history
…ce-Properties

support name and text in tree data source
  • Loading branch information
futuremint committed Oct 31, 2014
2 parents 61c42e3 + 976149f commit 23839d6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
12 changes: 7 additions & 5 deletions js/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

// -- BEGIN UMD WRAPPER PREFACE --

// For more information on UMD visit:
// For more information on UMD visit:
// https://github.com/umdjs/umd/blob/master/jqueryPlugin.js

(function (factory) {
Expand All @@ -21,7 +21,7 @@
}
}(function ($) {
// -- END UMD WRAPPER PREFACE --

// -- BEGIN MODULE CODE HERE --

var old = $.fn.tree;
Expand Down Expand Up @@ -77,10 +77,10 @@
if(value.type === 'folder') {
$entity = self.$element.find('[data-template=treebranch]:eq(0)').clone().removeClass('hide').removeAttr('data-template');
$entity.data(value);
$entity.find('.tree-branch-name > .tree-label').html(value.name);
$entity.find('.tree-branch-name > .tree-label').html(value.text || value.name);
} else if (value.type === 'item') {
$entity = self.$element.find('[data-template=treeitem]:eq(0)').clone().removeClass('hide').removeAttr('data-template');
$entity.find('.tree-item-name > .tree-label').html(value.name);
$entity.find('.tree-item-name > .tree-label').html(value.text || value.name);
$entity.data(value);
}

Expand All @@ -100,6 +100,8 @@
// 'id': guid
// }
// };
//
// the "name" attribute is also supported but is deprecated for "text".

// add attributes to tree-branch or tree-item
var attr = value['attr'] || value.dataAttributes || [];
Expand All @@ -110,7 +112,7 @@
case 'className':
$entity.addClass(value);
break;

// allow custom icons
case 'data-icon':
$entity.find('.icon-item').removeClass().addClass('icon-item ' + value);
Expand Down
17 changes: 17 additions & 0 deletions test/tree-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ define(function(require){
});
};

this.textDataSource = function (options, callback) {
callback({
data: [
{ text: 'node text', type: 'folder', attr: { id: 'folder1' } }
]
});
};

}
});

Expand Down Expand Up @@ -144,4 +152,13 @@ define(function(require){
equal(typeof( $tree.tree('destroy')) , 'string', 'returns string (markup)');
equal( $tree.parent().length, false, 'control has been removed from DOM');
});

test("Tree should accept TEXT as the NAME property in the datasource", function () {
var $tree = $(html).find('#MyTree');

$tree.tree({ dataSource: this.textDataSource});

$tree.tree('selectFolder', $tree.find('.tree-branch-name:eq(1)'));
equal($tree.tree('selectedItems')[0].text, 'node text', 'Param TEXT used in the datasource');
});
});

0 comments on commit 23839d6

Please sign in to comment.