Skip to content

Commit

Permalink
dropdownlist
Browse files Browse the repository at this point in the history
  • Loading branch information
ttt22703 committed Dec 21, 2015
1 parent 3ae90d5 commit c046ac1
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 24 deletions.
2 changes: 1 addition & 1 deletion library/sui/input/dropdownlist/sui.dropdownlist.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
ms-mouseover="_mouseover"
ms-repeat="_tempData" >
<span ms-visible="isMultiple" class="sui-input-dropdownlist-item-checkbox-span">
<input type="checkbox" >
<input ms-attr-id="sui-input-dropdownlist-{{inputid}}-{{$index}}" type="checkbox" ms-duplex-number="value" ms-attr-value="el[valueColumn]" ms-click="_checkboxClick">
</span>
<span class="sui-input-dropdownlist-item-span">
{{el[displayColumns[0]]}}
Expand Down
98 changes: 75 additions & 23 deletions library/sui/input/dropdownlist/sui.dropdownlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ define(["avalon", "text!./sui.dropdownlist.html", "css!../sui-input-common.css",
setFocus: _interface,
getValue: _interface,
_close: _interface,
_checkboxClick:_interface,
//配置项
did: "",
title: "",
Expand All @@ -43,11 +44,12 @@ define(["avalon", "text!./sui.dropdownlist.html", "css!../sui-input-common.css",
styleType: "normal",
isShowNoticeImage: false,
isMultiple: false, //是否多选
filterColumns:["text"], //过滤字段
displayColumns:["text"], //单选显示文本
valueColumn:"id", //值列
titleColumns:[], //多列标题
widthColumns:[],//多列列宽
filterColumns: ["text"], //过滤字段
displayColumns: ["text"], //单选显示文本
valueColumn: "id", //值列
displayColumn: "text",
titleColumns: [], //多列标题
widthColumns: [], //多列列宽
//模板
$template: template,
//替换自定义标签
Expand Down Expand Up @@ -82,30 +84,38 @@ define(["avalon", "text!./sui.dropdownlist.html", "css!../sui-input-common.css",
vm.msg = "";
}
//监控属性
// vm.$watch("value", function (n, o) {
// vm.onChange(n, o)
// vm.check()
// })
vm.$watch("value.length", function (n, o) {
//vm.onChange(n, o)
vm.check()
})
//监测data是否变化
vm.$watch("data", function (n, o) {
vm._tempData = vm.data;
if (vm.data.length > 8)
{
vm._listHeight = 8 * 25;
}
else
{
vm._listHeight = "";
}
})
},
$ready: function (vm, element) {
//给文本框赋初值。
avalon.each(vm.data, function (index, item) {
if (vm.value.indexOf(item.id) >= 0)
{
if (vm.inputid && vm.isMultiple==false)
if (vm.inputid && vm.isMultiple == false)
{
vm._tempValue=item[vm.displayColumns[0]];
vm._tempValue = item[vm.displayColumns[0]];
document.getElementById(vm.inputid).value = item[vm.displayColumns[0]];
}
}
})

vm.onInit(vm);

var arr = [
[document, "click", function (e) {
var target = e.target;
Expand Down Expand Up @@ -133,7 +143,12 @@ define(["avalon", "text!./sui.dropdownlist.html", "css!../sui-input-common.css",
vm._showNoticeImage = true;
return false
}

else
{
vm.msg = "";
vm._showNoticeImage = false;
return true;
}
return true;
}
vm._blur = function (e)
Expand Down Expand Up @@ -179,11 +194,19 @@ define(["avalon", "text!./sui.dropdownlist.html", "css!../sui-input-common.css",
}
vm._close = function ()
{

if (vm.inputid)
if (!vm.isMultiple)
{
if (vm.inputid)
{
document.getElementById(vm.inputid).value = vm._tempValue;
}
}
else
{
document.getElementById(vm.inputid).value = vm._tempValue;
document.getElementById(vm.inputid).value = vm.value.sort().join(";")
vm._tempData = vm.data;
}

vm._focusing = false;
if (vm.inputid)
{
Expand All @@ -192,16 +215,45 @@ define(["avalon", "text!./sui.dropdownlist.html", "css!../sui-input-common.css",
}
vm._itemClick = function (e, index)
{
vm.value.removeAll()
vm.value.push(vm._tempData[index][vm.valueColumn]);
vm._tempValue = vm._tempData[index][vm.displayColumns[0]];
if (!vm.isMultiple)
{
vm.value.removeAll()
vm.value.push(vm._tempData[index][vm.valueColumn]);
vm._tempValue = vm._tempData[index][vm.displayColumns[0]];

vm._focusing = false;
vm._isHover = false;
// if(vm._tempData.length!=vm.data.length)
vm._isHover = false;
vm._focusing = false;
vm._tempData = vm.data
}
else
{
//document.getElementById("sui-input-dropdownlist-" + vm.inputid + "-" + index).checked=!document.getElementById("sui-input-dropdownlist-" + vm.inputid + "-" + index).checked;
var tmpchecked = document.getElementById("sui-input-dropdownlist-" + vm.inputid + "-" + index).checked;
if (tmpchecked)
{
document.getElementById("sui-input-dropdownlist-" + vm.inputid + "-" + index).checked = false;
if (vm.value.indexOf(vm._tempData[index][vm.valueColumn]) >= 0)
{
vm.value.splice(vm.value.indexOf(vm._tempData[index][vm.valueColumn]),1)
}
}
else
{
document.getElementById("sui-input-dropdownlist-" + vm.inputid + "-" + index).checked = true;
if (vm.value.indexOf(vm._tempData[index][vm.valueColumn]) < 0)
{
vm.value.push(vm._tempData[index][vm.valueColumn])
}
}
}
}
vm._checkboxClick=function()
{
// if(event.preventDefault)
// {
vm._tempData = vm.data
// event.preventDefault();
// }
event.cancelBubble=true;
}
vm.setFocus = function ()
{
Expand Down

0 comments on commit c046ac1

Please sign in to comment.