有什么方法可以按名称对由select2生成的列表进行排序?我有一些代码:
var dataUser = [{
"id": "5",
"text": "BTest"
}, {
"id": "2",
"text": "ATest"
}, {
"id": "8",
"text": "CTest"
}, {
"id": "13",
"text": "DTest"
}];
$("#mylist").select2({
data: dataUser,
templateResult: function(data) {
return data.text;
},
sorter: function(data) {
return data.sort();
}
});
Run Code Online (Sandbox Code Playgroud)
http://jsfiddle.net/oe9retsL/4/
此列表按ID排序,但我想按文本排序。
我的OpenLayer3地图有问题。当我在地图上添加一些标记时,我想调整地图大小并更改缩放比例,以便在屏幕上设置所有标记。
我的代码如下:
/** CREATE MARKERS **/
for (var i=0;i<1;i++){
var iconFeature = new ol.Feature({
geometry: new
ol.geom.Point(ol.proj.transform([Math.random()*360-180, Math.random()*180-90], 'EPSG:4326', 'EPSG:3857'))
});
vectorSource.addFeature(iconFeature);
var newBound = ol.Bounds();
newBound.extend([Math.random()*360-180, Math.random()*180-90]);
map.zoomToExtent(newBound);
}
/** MARKER STYLE **/
var iconStyle = [
new ol.style.Style({
image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
anchor: [0.5, 46],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
opacity: 1,
scale: 0.07,
src: 'marker.png'
}))
})
];
/** ADD LAYER VECTOR **/
var vectorLayer = new ol.layer.Vector({
source: vectorSource,
style: iconStyle
});
/** INIT …Run Code Online (Sandbox Code Playgroud)