Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix select issue #60

Merged
merged 2 commits into from
Apr 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions example/app/components/changelog/changelog.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<section class="intro-content change-log">
<h1>更新日志</h1>
<ul class="timeline">

<li>
<h3>2.1.15</h3>
<p><em>2017-4-01</em></p>
<ul>
<li>Improve upload component and document</li>
<li>Readme update</li>
<li>Fix select compoent, can set ngModel when data not fill</li>
</ul>
</li>

Expand Down
38 changes: 24 additions & 14 deletions lib/Select/select.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,34 @@ class SelectController {
*/
setModel(currentValue) {
let isMatch = false,
self = this;
this.dataArray.map((group) => {
return group.options.map((option) => {
if (option.id === currentValue.id) {
isMatch = true;
if(!self.isRemote){
option._active = true;
self = this;

/**
* 没有填充好数据的组件,也能设置好
* 设置好数据的组件,就要匹配内容
*/
if (this.dataArray && this.dataArray.length > 0) {
this.dataArray.map((group) => {
return group.options.map((option) => {
if (option.id === currentValue.id) {
isMatch = true;
if (!self.isRemote) {
option._active = true;
}
self.ngModel = option;
}
self.ngModel = option;
}
});
});
});

if(isMatch){
this.inputValue = this.ngModel.name ? this.ngModel.name : '';
if (isMatch) {
this.inputValue = this.ngModel.name ? this.ngModel.name : '';
}
else {
this.inputValue = '';
}
}
else{
this.inputValue = '';
else {
this.inputValue = this.ngModel.name ? this.ngModel.name : '';
}
}

Expand Down
12 changes: 10 additions & 2 deletions lib/Select/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,11 @@ describe('Select', () => {
*/
$rootScope.city = $rootScope.data[0];
$rootScope.$digest()
/**
* 期望UI展示的结果是 北京通州广场
*/
expect(finder.find('.f-input_inner').val()).to.equal($rootScope.data[0].name);
})
});

})

Expand Down Expand Up @@ -335,6 +338,12 @@ describe('Select', () => {
expect(finder.find('.f-select').hasClass('active')).to.be.false;
}))

it('[2.4.8]给一个尚未填充数据的remote组件设置ngModel,应该有效',()=>{
$rootScope.city = mockData.getData(false)[0];
$rootScope.$digest()
expect(finder.find('.f-input_inner').val()).to.equal($rootScope.city.name);
})

})

describe('[2.5]测试 is-multiple', () => {
Expand Down Expand Up @@ -399,7 +408,6 @@ describe('Select', () => {

it('禁用不可点击',()=>{
finder.find('.f-input').triggerHandler('click');
console.log(finder.find('.f-select'));
///TODO
})
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fancyui",
"version": "2.1.15",
"version": "2.1.16",
"description": "angular ui components",
"main": "./index.js",
"scripts": {
Expand Down