Commit a331169a authored by campaign's avatar campaign

修改setData和修复getCommonAncestor

parent 14fba533
...@@ -20,7 +20,7 @@ describe("node", function () { ...@@ -20,7 +20,7 @@ describe("node", function () {
it('first contain first',function(){ it('first contain first',function(){
expect(first.contains(first)).toBeTruthy(); expect(first.contains(first)).toBeTruthy();
}); });
}) });
describe('getCommonAncestor',function(){ describe('getCommonAncestor',function(){
it('first second commonAncestor is root',function(){ it('first second commonAncestor is root',function(){
expect(first.getCommonAncestor(second)).toBe(root); expect(first.getCommonAncestor(second)).toBe(root);
...@@ -30,9 +30,30 @@ describe("node", function () { ...@@ -30,9 +30,30 @@ describe("node", function () {
}); });
it('second.first first.first commonAncestor is root',function(){ it('second.first first.first commonAncestor is root',function(){
var a = first.getFirstChild(),b=second.getFirstChild(); var a = first.getFirstChild(),b=second.getFirstChild();
debugger
var c = a.getCommonAncestor(b);
expect(a.getCommonAncestor(b)).toBe(root); expect(a.getCommonAncestor(b)).toBe(root);
}); });
}) });
describe('setData',function(){
it('name and value both exist',function(){
root.setData('test',1);
expect(root.getData('test')).toBe(1);
});
it('name only exist clear property',function(){
root.setData('test');
expect(root.getData('test')).toBeUndefined();
});
it('name is object',function(){
root.setData({
'test':1
});
expect(root.getData('test')).toBe(1);
});
it('name and value both empty',function(){
root.setData('test',1);
root.setData('test1',2);
root.setData();
expect(root.getData('test')).toBeUndefined();
expect(root.getData('test1')).toBeUndefined();
});
});
}); });
\ No newline at end of file
...@@ -137,13 +137,19 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", { ...@@ -137,13 +137,19 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
}, },
setData: function ( name, value ) { setData: function ( name, value ) {
if ( arguments.length == 1 && typeof ( arguments[ 0 ] ) == 'object' ) { if(name === undefined){
Utils.extend( this.data, arguments[ 0 ] ); this.data = {}
}else if(utils.isObject(name)){
utils.extend(this.data,name)
}else{
if(value === undefined){
this.data[name] = null;
delete this.data[name]
}else{
this.data[name] = value;
}
} }
this.data[ name ] = value;
},
clearData: function () {
this.data = {};
}, },
getRenderContainer: function () { getRenderContainer: function () {
return this.rc; return this.rc;
...@@ -158,9 +164,9 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", { ...@@ -158,9 +164,9 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
if ( node.contains( this ) ) { if ( node.contains( this ) ) {
return node return node
} }
var parent = node.parent; var parent = this.parent;
while ( !parent.contains( node ) ) { while ( !parent.contains( node ) ) {
parent = parent.parentNode; parent = parent.parent;
} }
return parent; return parent;
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment