czl032405 / amazeui-areaselect Goto Github PK
View Code? Open in Web Editor NEWamazeui-plugin amazeui-areaselect
License: MIT License
amazeui-plugin amazeui-areaselect
License: MIT License
我说的这个forin循环处理object的bug可能大部分时候不存在,但是一出现就会在选项中增加一个属性
一共19个元素结果输出了20个 适应某个js或者浏览器在处理object的时候给对象加了一些属性。
具体问题代码为
{
key: "buildList",
value: function buildList(subArea) {
var plugin = this;
var options = this.options;
var $list = null;
//查找已经存在的list
$(".am-areaselect-list", this.$popup).not("am-tmpl").each(function (idx, ele) {
if ($(ele).data('subArea') == subArea) {
$list = $(ele);
}
});
//构建list
if (!$list) {
$list = $(".am-areaselect-list.am-tmpl", this.$popup).clone().removeClass("am-tmpl am-hide").data('subArea', subArea);
$list.appendTo($(".am-areaselect-lists", this.$popup));
for (var i in subArea) {
var $item = $(".am-areaselect-item.am-tmpl", $list).clone().removeClass("am-tmpl am-hide").text(subArea[i][options.areaNameKey]).data('value', subArea[i][options.areaValueKey]);
$item.appendTo($list);
(function (_i) {
$item.on("click", function (e) {
e.preventDefault();
if ($(this).hasClass("am-btn-primary") || $(this).siblings().hasClass("am-btn-primary")) {
plugin.selectedArea.pop();
}
$(this).addClass("am-btn-primary").siblings().removeClass("am-btn-primary");
plugin.select(subArea[_i]);
});
})(i);
}
}
$list.siblings(".am-areaselect-list").addClass("am-hide");
}
}
将for in 改成$.map就可以很好的解决这个问题,但是这又引入了jquery依赖,我不知道是否有更好的不依赖jquery的方式,所以没有提交pr。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.