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

对选项组增加按值选中功能 #15

Merged
merged 2 commits into from Sep 3, 2012
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/esui/BoxGroup.js
Expand Up @@ -70,6 +70,33 @@ esui.BoxGroup.prototype = {
}
},

/**
* 对选项组下所有选项进行按值选中
*
* @public
* @param {Array} values
*/
selectByValues: function(values) {
var boxes = this.getBoxList(),
len = boxes.length,
i = 0,
box,
v = 0,
vLen = values.length;

for ( i = 0 ; i < len; i++ ) {
box = boxes[i];
box.setChecked(false);
value = box.getValue();
for ( v = 0 ; v < vLen; v++) {
if (value == values[v]) {
box.setChecked(true);
break;
}
}
}
},

/**
* 对选项组下所有选项进行反选
*
Expand Down
58 changes: 37 additions & 21 deletions test/esui/checkbox_and_radio.html
Expand Up @@ -26,27 +26,35 @@
<body>
<div class="header">[ESUI EXAMPLE] - CheckBox and Radio</div>
<div class="main">
<table cellpadding="5" cellspacing="0" border="0">
<tr>
<td><input type="checkbox" value="1" ui="type:CheckBox;id:cb1" title="one" name="num"/></td>
<td><input type="checkbox" value="2" ui="type:CheckBox;id:cb2" title="two" name="num"/></td>
<td><input type="checkbox" value="3" ui="type:CheckBox;id:cb3" title="three" name="num"/></td>
<td><div ui="type:Button;id:currCb">当前选中</div></td>
<td><div ui="type:Button;id:selAll">全选</div></td>
<td><div ui="type:Button;id:selInv">反选</div></td>
</tr>
<tr>
<td><input type="radio" value="1" ui="type:Radio;id:r1" title="one" name="num2"/></td>
<td><input type="radio" value="2" ui="type:Radio;id:r2" title="two" name="num2"/></td>
<td><input type="radio" value="3" ui="type:Radio;id:r3" title="three" name="num2"/></td>
<td colspan="3"><div ui="type:Button;id:currRadio">当前选中</div></td>
</tr>
<tr>
<td><input type="radio" value="1" ui="type:Radio;id:x1" title="one"/></td>
<td><input type="checkbox" value="3" ui="type:CheckBox;id:x3" title="three"/></td>
<td colspan="3"><div ui="type:Button;id:xRender">Call Render Again</div></td>
</tr>
</table>
<p>
<input type="checkbox" value="1" ui="type:CheckBox;id:cb1" title="one" name="num"/>
<input type="checkbox" value="2" ui="type:CheckBox;id:cb2" title="two" name="num"/>
<input type="checkbox" value="3" ui="type:CheckBox;id:cb3" title="three" name="num"/>
</p>
<div>
<div ui="type:Button;id:currCb">当前选中</div>
<div ui="type:Button;id:selAll">全选</div>
<div ui="type:Button;id:selInv">反选</div>
<div ui="type:Button;id:selValues">选中值为2,3的项</div>
</div>

<p>
<input type="radio" value="1" ui="type:Radio;id:r1" title="one" name="num2"/>
<input type="radio" value="2" ui="type:Radio;id:r2" title="two" name="num2"/>
<input type="radio" value="3" ui="type:Radio;id:r3" title="three" name="num2"/>
</p>
<div>
<div ui="type:Button;id:currRadio">当前选中</div>
<div ui="type:Button;id:radioSelValues">选中值为2的项</div>
</div>

<p>
<input type="radio" value="1" ui="type:Radio;id:x1" title="one"/>
<input type="checkbox" value="3" ui="type:CheckBox;id:x3" title="three"/>
</p>
<div>
<div ui="type:Button;id:xRender">Call Render Again</div>
</div>
</div>

<script>
Expand All @@ -66,13 +74,21 @@
esui.get('cb1').getGroup().selectInverse();
};

esui.get('selValues').onclick = function () {
esui.get('cb1').getGroup().selectByValues([2, 3]);
};

esui.get('currRadio').onclick = function () {
alert( 'checked one:' + esui.get('r1').isChecked() );
alert( 'checked two:' + esui.get('r2').isChecked() );
alert( 'checked three:' + esui.get('r3').isChecked() );
alert( 'group value:' + esui.get('r3').getGroup().getValue() );
};

esui.get('radioSelValues').onclick = function () {
esui.get('r2').getGroup().selectByValues([2]);
};

esui.get('xRender').onclick = function() {
esui.get('x1').render();
esui.get('x3').render();
Expand Down