From 13abc3a611f0927353c08edd414e9d0aa4126644 Mon Sep 17 00:00:00 2001 From: Meowtec Date: Wed, 14 Oct 2015 10:25:56 +0800 Subject: [PATCH 1/3] fix defaultSelected bug --- src/select.handlebars | 8 ++++---- src/select.js | 16 ++++++++-------- tests/select-spec.js | 30 +++++++++++++++--------------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/select.handlebars b/src/select.handlebars index da1ab41..5abb162 100644 --- a/src/select.handlebars +++ b/src/select.handlebars @@ -1,12 +1,12 @@
diff --git a/src/select.js b/src/select.js index 97cc1f5..d8ce2b2 100644 --- a/src/select.js +++ b/src/select.js @@ -63,7 +63,7 @@ var Select = Overlay.extend({ }, templateHelpers: { - output: function(data) { + toString: function(data) { return data + ''; } }, @@ -162,10 +162,10 @@ var Select = Overlay.extend({ // 同步 html 到 model var model = this.get('model'); if (oldSelectIndex >= 0) { - model.select[oldSelectIndex].selected = false; + model.options[oldSelectIndex].selected = false; } if (selectIndex >= 0) { - model.select[selectIndex].selected = true; + model.options[selectIndex].selected = true; } this.set('model', model); @@ -206,7 +206,7 @@ var Select = Overlay.extend({ }, addOption: function(option) { - var model = this.get("model").select; + var model = this.get("model").options; model.push(option); this.syncModel(model); return this; @@ -235,7 +235,7 @@ var Select = Overlay.extend({ enableOption: function(option) { var index = getOptionIndex(option, this.options); - var model = this.get("model").select; + var model = this.get("model").options; model[index].disabled = false; this.syncModel(model); return this; @@ -243,7 +243,7 @@ var Select = Overlay.extend({ disableOption: function(option) { var index = getOptionIndex(option, this.options); - var model = this.get("model").select; + var model = this.get("model").options; model[index].disabled = true; this.syncModel(model); return this; @@ -416,7 +416,7 @@ function convertSelect(select, classPrefix) { if (!hasDefaultSelect && model.length) { model[0].selected = 'true'; } - return {select: model, classPrefix: classPrefix}; + return {options: model, classPrefix: classPrefix}; } // 补全 model 对象 @@ -438,7 +438,7 @@ function completeModel(model, classPrefix) { } else { //当所有都没有设置 selected 则默认设置第一个 newModel[0].selected = true; } - return {select: newModel, classPrefix: classPrefix}; + return {options: newModel, classPrefix: classPrefix}; } function getOptionIndex(option, options) { diff --git a/tests/select-spec.js b/tests/select-spec.js index 0e0f4c4..8bad419 100644 --- a/tests/select-spec.js +++ b/tests/select-spec.js @@ -54,7 +54,7 @@ describe('select', function() { trigger: '#example' }).render(); - var model = select.get("model").select; + var model = select.get("model").options; expect(model[0].defaultSelected).to.be(false); expect(model[0].selected).to.be(true); expect(model[0].value).to.be('value1'); @@ -71,7 +71,7 @@ describe('select', function() { trigger: '#example' }).render(); - var model = select.get("model").select; + var model = select.get("model").options; expect(model[0].defaultSelected).to.be(false); expect(model[0].selected).to.be(false); expect(model[0].value).to.be('value1'); @@ -88,7 +88,7 @@ describe('select', function() { trigger: '#example' }).render(); - var model = select.get("model").select; + var model = select.get("model").options; expect(model[0].disabled).to.be(false); expect(model[1].disabled).to.be(true); }); @@ -99,7 +99,7 @@ describe('select', function() { trigger: '#example' }).render(); - var model = select.get("model").select; + var model = select.get("model").options; expect(model[0].defaultSelected).to.be(true); expect(model[0].selected).to.be(false); expect(model[0].value).to.be('value1'); @@ -120,7 +120,7 @@ describe('select', function() { ] }).render(); - var model = select.get("model").select; + var model = select.get("model").options; expect(model[0].defaultSelected).to.be(false); expect(model[0].selected).to.be(true); expect(model[0].value).to.be('value1'); @@ -141,7 +141,7 @@ describe('select', function() { ] }).render(); - var model = select.get("model").select; + var model = select.get("model").options; expect(model[0].defaultSelected).to.be(false); expect(model[0].selected).to.be(false); expect(model[0].value).to.be('value1'); @@ -162,7 +162,7 @@ describe('select', function() { ] }).render(); - var model = select.get("model").select; + var model = select.get("model").options; expect(model[0].defaultSelected).to.be(true); expect(model[0].selected).to.be(false); expect(model[0].value).to.be('value1'); @@ -179,7 +179,7 @@ describe('select', function() { trigger: '#example' }).render(); - var model = select.get("model").select; + var model = select.get("model").options; expect(model.length).to.be(0); }); @@ -639,11 +639,11 @@ describe('select', function() { ] }).render(); select.select(0); - expect(select.get('model').select[0].selected).to.be.ok(); + expect(select.get('model').options[0].selected).to.be.ok(); select.select(1); - expect(select.get('model').select[1].selected).to.be.ok(); + expect(select.get('model').options[1].selected).to.be.ok(); select.select(2); - expect(select.get('model').select[2].selected).to.be.ok(); + expect(select.get('model').options[2].selected).to.be.ok(); }); it('html original select should be visiable', function() { @@ -666,9 +666,9 @@ describe('select', function() { {value: 'value4', text: 'text4', selected: true} ] }).render(); - expect(select.get('model').select[0].selected).not.to.be.ok(); - expect(select.get('model').select[1].selected).not.to.be.ok(); - expect(select.get('model').select[2].selected).not.to.be.ok(); - expect(select.get('model').select[3].selected).to.be.ok(); + expect(select.get('model').options[0].selected).not.to.be.ok(); + expect(select.get('model').options[1].selected).not.to.be.ok(); + expect(select.get('model').options[2].selected).not.to.be.ok(); + expect(select.get('model').options[3].selected).to.be.ok(); }) }); From 8dce350fad3b5fb122a5ecfde9213cc032d08667 Mon Sep 17 00:00:00 2001 From: Meowtec Date: Wed, 14 Oct 2015 10:26:22 +0800 Subject: [PATCH 2/3] @import for spm3.6.11 --- index.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.css b/index.css index 919626a..264873c 100644 --- a/index.css +++ b/index.css @@ -1 +1 @@ -@import url("alice-select"); +@import url("~alice-select"); From 10d33b59a3f8bef838341a9c2f4daaaba9c5c3a2 Mon Sep 17 00:00:00 2001 From: Meowtec Date: Wed, 14 Oct 2015 10:27:37 +0800 Subject: [PATCH 3/3] ignore corerage --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 312f307..fb76e4b 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ sea-modules _site dist spm_modules +coverage