Skip to content

Commit

Permalink
add ngModels for isMultiple
Browse files Browse the repository at this point in the history
  • Loading branch information
guanbingchang committed Mar 22, 2017
1 parent 4378997 commit 529d56e
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 99 deletions.
33 changes: 24 additions & 9 deletions example/app/components/select/select.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
*/

export default class SelectController {
constructor($state, $q,$timeout) {
constructor($state, $q, $timeout,$scope) {
'ngInject'
this.$state = $state;
this.$q = $q;
this.$timeout = $timeout;
this.$scope = $scope;

this.cityGroup = {};

Expand Down Expand Up @@ -51,11 +52,11 @@ export default class SelectController {
{ id: '1005', name: '深圳', disabled: true }
]


this.data2 = angular.copy(this.data);
this.city2 = this.data2[0];


this.data3 = angular.copy(this.data);
this.city3 = {};

Expand All @@ -66,30 +67,44 @@ export default class SelectController {
{ id: '1004', name: '武汉万达广场' },
{ id: '1005', name: '浙江椒江万达广场' }
];
this.city4 = {};
this.cities = {};

this.data6 = [
{ id: '1001', name: '上海江桥万达广场' },
{ id: '1002', name: '北京通州万达广场' },
{ id: '1003', name: '上海周浦万达广场' },
{ id: '1004', name: '武汉万达广场' },
{ id: '1005', name: '浙江椒江万达广场' }
];
this.cities1 = {};

this.data5 = [{ id: '1001', name: '上海' },
{ id: '1002', name: '北京' },
{ id: '1003', name: '广州' },
{ id: '1004', name: '杭州' },
{ id: '1005', name: '深圳' }];
this.city5 ={};
this.city5 = {};
this.city6 = {};
}

onSelect($item) {
console.log($item);
}


change(){
this.city6 = {name:'北京',id:'1002'};
}

mockData($value) {
let deferred = this.$q.defer();
let returnData = this.data.filter((d) => {
return d.name.indexOf($value) > -1;
})
console.log($value);
this.$timeout(function(){
this.$timeout(function () {
deferred.resolve(returnData);
},300)
}, 300)

return deferred.promise;
}

Expand Down
18 changes: 10 additions & 8 deletions example/app/components/select/select.html
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ <h3>{{'Example'|translate}}</h3>
<div class="bs-example pop-confirm-example">
<f-select
data="vm.data4"
ng-model="vm.city4"
ng-models="vm.cities1"
is-multiple="true"
on-item-selected="vm.onSelect($item)"
></f-select>
Expand All @@ -233,7 +233,7 @@ <h3>view</h3>
<div hljs-no-escape class="highlight no-border" hljs >
&lt;f-select
data="vm.data"
ng-model="vm.city"
ng-models="vm.cities"
is-multiple="true"
on-item-selected="vm.onSelect($item)"
&lt;/f-select&gt;</div>
Expand All @@ -251,7 +251,7 @@ <h3>controller</h3>
{ id: '1004', name: '武汉万达广场' },
{ id: '1005', name: '浙江椒江万达广场' }
];
this.city = {};
this.cities = {};
}
}</div>
</div>
Expand All @@ -265,9 +265,9 @@ <h3>{{'Example'|translate}}</h3>
<div class="example-block">
<div class="bs-example pop-confirm-example">
<f-select
data="vm.data4"
data="vm.data6"
allow-create="true"
ng-model="vm.city4"
ng-models="vm.cities"
is-multiple="true"
on-item-selected="vm.onSelect($item)"
></f-select>
Expand All @@ -280,7 +280,7 @@ <h3>view</h3>
&lt;f-select
data="vm.data"
allow-create="true"
ng-model="vm.city"
ng-models="vm.cities"
is-multiple="true"
on-item-selected="vm.onSelect($item)"
&lt;/f-select&gt;</div>
Expand All @@ -298,7 +298,7 @@ <h3>controller</h3>
{ id: '1004', name: '武汉万达广场' },
{ id: '1005', name: '浙江椒江万达广场' }
];
this.city = {};
this.cities = {};
}
}</div>
</div>
Expand Down Expand Up @@ -373,13 +373,15 @@ <h3>{{'Example'|translate}}</h3>
remote-debounce="300"
remote-method="vm.mockData($value)"
data="vm.data"
ng-model="vm.city"
ng-model="vm.city6"
empty-data-text="'无城市数据'"
on-item-selected="vm.onSelect($item)"
></f-select>
</div>
</div>

<button ng-click="vm.change();">change </button>

<h3>view</h3>
<div class="example-block">
<div hljs-no-escape class="highlight no-border" hljs >
Expand Down
9 changes: 8 additions & 1 deletion lib/Select/select.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ let selectComponent = {
isGroup : "<",
isDisabled:'<',
data:'<',
ngModel:'=',
/**
* 单向绑定,可以二次设置来清空
*/
ngModel:'<',
/**
* 双向绑定,给isMultiple模式用的数组
*/
ngModels:'=',
onItemSelected:'&',
remoteMethod:'&',
remoteDebounce:'<',
Expand Down
Loading

0 comments on commit 529d56e

Please sign in to comment.