我想升级到 lasted stable angular branch 1.4.7。我来自 1.2.13。 我的项目中有一个针对应用程序定制的 angular-leaflet-directive。我想弄清楚如何更改函数中的语法,以免引发错误。 控制台消息
Error: [$parse:syntax] Syntax Error: Token '.50465' is an unexpected token at column 8 of the expression [markers.50465] starting at [.50465].
http://errors.angularjs.org/1.4.7/$parse/syntax?p0=.50465&p1=is%20an%20unexpected%20token&p2=8&p3=markers.50465&p4=.50465
at angular.js:68
at Object.AST.throwError (angular.js:13057)
at Object.AST.ast (angular.js:12827)
at Object.ASTCompiler.compile (angular.js:13276)
at Parser.parse (angular.js:14146)
at $parse (angular.js:14248)
at Scope.$watch (angular.js:15412)
at createMarker (angular-leaflet-directive.js:1496)
at Object.fn (angular-leaflet-directive.js:1158)
at Scope.$digest (angular.js:15826)(anonymous function) @ angular.js:12477(anonymous function) @ angular.js:9246Scope.$digest @ angular.js:15844Scope.$apply @ angular.js:16097done @ angular.js:10546completeRequest @ angular.js:10744requestLoaded @ angular.js:10685
函数 错误在“标记”处。
// add new markers
for (var new_name in newMarkers) {
if (markers[new_name] === undefined) {
var newMarker = createMarker('markers.' + new_name, $scope.markers[new_name], map);
if (newMarker !== null) {
markers[new_name] = newMarker;
}
}
}
第 1496 行从这里开始。
var clearWatch = $scope.$watch(scope_watch_name, function (data, old_data) {
if (!data) {
marker.closePopup();
// There is no easy way to know if a marker is added to a layer, so we search for it
// if there are overlays
if (layers !== undefined && layers !== null) {
if (layers.overlays !== undefined) {
for (var key in layers.overlays) {
if (layers.overlays[key] instanceof L.LayerGroup) {
if (layers.overlays[key].hasLayer(marker)) {
layers.overlays[key].removeLayer(marker);
}
}
}
}
}
map.removeLayer(marker);
clearWatch();
return;
}
if (old_data) {
//TODO Check for layers !== null
//TODO Check for layers.overlays !== null !== undefined
// It is possible the the layer has been removed or the layer marker does not exist
// Update the layer group if present or move it to the map if not
if (data.layer === undefined || data.layer === null || typeof data.layer !== 'string') {
// There is no layer information, we move the marker to the map if it was in a layer group
if (old_data.layer !== undefined && old_data.layer !== null && typeof old_data.layer === 'string') {
// Remove from the layer group that is supposed to be
if (layers.overlays[old_data.layer] !== undefined) {
if (layers.overlays[old_data.layer].hasLayer(marker)) {
layers.overlays[old_data.layer].removeLayer(marker);
// If the marker had a popup we close it because we do not know if the popup in on the map
// or on the layer group. This is ineficient, but as we can't check if the popup is opened
// in Leaflet we can't determine if it has to be open in the new layer. So removing the
// layer group of a marker always closes the popup.
// TODO: Improve popup behaviour when removing a marker from a layer group
marker.closePopup();
}
}
// Test if it is not on the map and add it
if (!map.hasLayer(marker)) {
map.addLayer(marker);
}
}
} else if (old_data.layer === undefined || old_data.layer === null || old_data.layer !== data.layer) {
// If it was on a layer group we have to remove it
if (typeof old_data.layer === 'string') {
if (layers.overlays[old_data.layer] !== undefined) {
if (layers.overlays[old_data.layer].hasLayer(marker)) {
layers.overlays[old_data.layer].removeLayer(marker);
}
}
}
// If the marker had a popup we close it because we do not know how the new layer
// will be. This is ineficient, but as we can't check if the opoup is opened in Leaflet
// we can't determine if it has to be open in the new layer. So changing the layer group
// of a marker always closes the popup.
// TODO: Improve popup behaviour when changing a marker from a layer group
marker.closePopup();
// Remove it from the map in case the new layer is hidden or there is an error in the new layer
if (map.hasLayer(marker)) {
map.removeLayer(marker);
}
// The data.layer is defined so we add the marker to the layer if it is different from the old data
if (layers.overlays[data.layer] !== undefined) {
// Is a group layer?
var layerGroup = layers.overlays[data.layer];
if (layerGroup instanceof L.LayerGroup) {
// The marker goes to a correct layer group, so first of all we add it
layerGroup.addLayer(marker);
// The marker is automatically added to the map depending on the visibility
// of the layer, so we only have to open the popup if the marker is in the map
if (map.hasLayer(marker)) {
if (data.focus === true) {
marker.openPopup();
}
}
} else {
$log.error('[AngularJS - Leaflet] A marker can only be added to a layer of type "group"');
}
} else {
$log.error('[AngularJS - Leaflet] You must use a name of an existing layer');
}
} else {
// Never has to enter here...
}
// Update the draggable property
if (data.draggable === undefined || data.draggable === null || data.draggable !== true) {
// If there isn't or wasn't the draggable property or is false and previously true update the dragging
// the !== true prevents for not boolean values in the draggable property
if (old_data.draggable !== undefined && old_data.draggable !== null && old_data.draggable === true) {
if (marker.dragging) {
marker.dragging.disable();
}
}
} else if (old_data.draggable === undefined || old_data.draggable === null || old_data.draggable !== true) {
// The data.draggable property must be true so we update if there wasn't a previous value or it wasn't true
if (marker.dragging) {
marker.dragging.enable();
} else {
if (L.Handler.MarkerDrag) {
marker.dragging = new L.Handler.MarkerDrag(marker);
marker.options.draggable = true;
marker.dragging.enable();
}
}
}
if (data.zIndexOffset && data.zIndexOffset != old_data.zIndexOffset) {
marker.setZIndexOffset(data.zIndexOffset);
}
// Update the icon property
if (data.icon === undefined || data.icon === null || typeof data.icon !== 'object') {
// If there is no icon property or it's not an object
if (old_data.icon !== undefined && old_data.icon !== null && typeof old_data.icon === 'object') {
// If there was an icon before restore to the default
marker.setIcon(new LeafletIcon());
marker.closePopup();
marker.unbindPopup();
if (data.message !== undefined && data.message !== null && typeof data.message === 'string' && data.message !== "") {
marker.bindPopup(data.message, {
autoPan: data.popupOptions ? (data.popupOptions.autoPan ? true : false) : true
});
}
}
} else if (old_data.icon === undefined || old_data.icon === null || typeof old_data.icon !== 'object') {
// The data.icon exists so we create a new icon if there wasn't an icon before
var dragA = false;
if (marker.dragging) {
dragA = marker.dragging.enabled();
}
if (Helpers.AwesomeMarkersPlugin.is(data.icon)) {
// This icon is a L.AwesomeMarkers.Icon so it is using the AwesomeMarker PlugIn
marker.setIcon(data.icon);
// As the new icon creates a new DOM object some elements, as drag, are reseted.
} else if (Helpers.Leaflet.DivIcon.is(data.icon) || Helpers.Leaflet.Icon.is(data.icon)) {
// This is a Leaflet.DivIcon or a Leaflet.Icon
marker.setIcon(data.icon);
} else {
// This icon is a icon set in the model trough options
marker.setIcon(new LeafletIcon(data.icon));
}
if (dragA) {
marker.dragging.enable();
}
marker.closePopup();
marker.unbindPopup();
if (data.message !== undefined && data.message !== null && typeof data.message === 'string' && data.message !== "") {
marker.bindPopup(data.message, {
autoPan: data.popupOptions ? (data.popupOptions.autoPan ? true : false) : true
});
}
} else {
if (Helpers.AwesomeMarkersPlugin.is(data.icon)) {
// This icon is a L.AwesomeMarkers.Icon so it is using the AwesomeMarker PlugIn
if (!Helpers.AwesomeMarkersPlugin.equal(data.icon, old_data.icon)) {
var dragD = false;
if (marker.dragging) {
dragD = marker.dragging.enabled();
}
marker.setIcon(data.icon);
// As the new icon creates a new DOM object some elements, as drag, are reseted.
if (dragD) {
marker.dragging.enable();
}
//TODO: Improve depending on anchorPopup
// metrostudy
marker.closePopup();
if (marker._popup && marker._popup._isOpen) {
marker.unbindPopup();
}
if (data.message !== undefined && data.message !== null && typeof data.message === 'string' && data.message !== "") {
marker.bindPopup(data.message, {
autoPan: data.popupOptions ? (data.popupOptions.autoPan ? true : false) : true
});
}
}
} else if (Helpers.Leaflet.DivIcon.is(data.icon)) {
// This is a Leaflet.DivIcon
if (!Helpers.Leaflet.DivIcon.equal(data.icon, old_data.icon)) {
var dragE = false;
if (marker.dragging) {
dragE = marker.dragging.enabled();
}
marker.setIcon(data.icon);
// As the new icon creates a new DOM object some elements, as drag, are reseted.
if (dragE) {
marker.dragging.enable();
}
//TODO: Improve depending on anchorPopup
marker.closePopup();
marker.unbindPopup();
if (data.message !== undefined && data.message !== null && typeof data.message === 'string' && data.message !== "") {
marker.bindPopup(data.message, {
autoPan: data.popupOptions ? (data.popupOptions.autoPan ? true : false) : true
});
}
}
} else if (Helpers.Leaflet.Icon.is(data.icon)) {
// This is a Leaflet.DivIcon
if (!Helpers.Leaflet.Icon.equal(data.icon, old_data.icon)) {
var dragF = false;
if (marker.dragging) {
dragF = marker.dragging.enabled();
}
marker.setIcon(data.icon);
// As the new icon creates a new DOM object some elements, as drag, are reseted.
if (dragF) {
marker.dragging.enable();
}
//TODO: Improve depending on anchorPopup
// metrostudy
//marker.closePopup();
//marker.unbindPopup();
//if (data.message !== undefined && data.message !== null && typeof data.message === 'string' && data.message !== "") {
// marker.bindPopup(data.message, {
// autoPan: data.popupOptions ? (data.popupOptions.autoPan ? true : false) : true
// });
//}
}
} else {
// This icon is an icon defined in the marker model through options
// There is an icon and there was an icon so if they are different we create a new icon
if (JSON.stringify(data.icon) !== JSON.stringify(old_data.icon)) {
var dragG = false;
if (marker.dragging) {
dragG = marker.dragging.enabled();
}
marker.setIcon(new LeafletIcon(data.icon));
if (dragG) {
marker.dragging.enable();
}
//TODO: Improve depending on anchorPopup
marker.closePopup();
marker.unbindPopup();
if (data.message !== undefined && data.message !== null && typeof data.message === 'string' && data.message !== "") {
marker.bindPopup(data.message, {
autoPan: data.popupOptions ? (data.popupOptions.autoPan ? true : false) : true
});
}
}
}
}
// Update the Popup message property
if (data.message === undefined || data.message === null || typeof data.message !== 'string' || data.message === "") {
// There is no popup to show, so if it has previously existed it must be unbinded
if (old_data.message !== undefined && old_data.message !== null && typeof old_data.message === 'string' && old_data.message !== "") {
marker.closePopup();
marker.unbindPopup();
}
} else {
// There is some text in the popup, so we must show the text or update existing
if (old_data.message === undefined || old_data.message === null || typeof old_data.message !== 'string' || old_data.message === "") {
// There was no message before so we create it
marker.bindPopup(data.message, {
autoPan: data.popupOptions ? (data.popupOptions.autoPan ? true : false) : true
});
} else if (data.message !== old_data.message) {
// There was a different previous message so we update it
marker.setPopupContent(data.message);
}
}
// Update the focus property
if (data.focus && !old_data.focus) {
// The data.focus property must be true so we update if there wasn't a previous value or it wasn't true
marker.openPopup();
}
// Update the lat-lng property (always present in marker properties)
if (data.lat === undefined || data.lat === null || isNaN(data.lat) || typeof data.lat !== 'number' || data.lng === undefined || data.lng === null || isNaN(data.lng) || typeof data.lng !== 'number') {
$log.warn('There are problems with lat-lng data, please verify your marker model');
// Remove the marker from the layers and map if it is not valid
if (layers !== null) {
if (layers.overlays !== undefined && layers.overlays !== null) {
for (var olname in layers.overlays) {
if (layers.overlays[olname] instanceof L.LayerGroup || Helpers.MarkerClusterPlugin.is(layers.overlays[olname])) {
if (layers.overlays[olname].hasLayer(marker)) {
layers.overlays[olname].removeLayer(marker);
}
}
}
}
}
map.removeLayer(marker);
} else {
var cur_latlng = marker.getLatLng();
// On dragend event, scope will be updated, which
// tirggers this watch expression. Then we call
// setLatLng and triggers move event on marker and
// causes digest already in progress error.
//
// This check is to make sure we don't trigger move
// event manually after dragend, which is redundant
// anyway. Because before dragend event fired, marker
// sate is already updated by leaflet.
if (cur_latlng.lat !== data.lat || cur_latlng.lng !== data.lng) {
// if the marker is in a clustermarker layer it has to be removed and added again to the layer
var isCluster = false;
if (data.layer !== undefined && data.layer !== null && typeof data.layer === 'string') {
if (Helpers.MarkerClusterPlugin.is(layers.overlays[data.layer])) {
layers.overlays[data.layer].removeLayer(marker);
isCluster = true;
}
}
marker.setLatLng([data.lat, data.lng]);
if (isCluster) {
layers.overlays[data.layer].addLayer(marker);
}
}
}
}
}, true);
最佳答案
您正在尝试通过属性点表示法 访问数组元素。这不是一个有效的构造,您需要使用方括号表示法 - []。
问题来自 markers.12345 的监视表达式,它取自 createMarker('markers.' + name, ...)。所以不要写成 createMarker('markers[' + name + ']', ...)。
关于javascript - Angular 更新后如何更正语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33586771/
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我脑子里浮现出一些关于一种新编程语言的想法,所以我想我会尝试实现它。一位friend建议我尝试使用Treetop(Rubygem)来创建一个解析器。Treetop的文档很少,我以前从未做过这种事情。我的解析器表现得好像有一个无限循环,但没有堆栈跟踪;事实证明很难追踪到。有人可以指出入门级解析/AST指南的方向吗?我真的需要一些列出规则、常见用法等的东西来使用像Treetop这样的工具。我的语法分析器在GitHub上,以防有人希望帮助我改进它。class{initialize=lambda(name){receiver.name=name}greet=lambda{IO.puts("He
我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚
Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack
在选择我想要运行操作的频率时,唯一的选项是“每天”、“每小时”和“每10分钟”。谢谢!我想为我的Rails3.1应用程序运行调度程序。 最佳答案 这不是一个优雅的解决方案,但您可以安排它每天运行,并在实际开始工作之前检查日期是否为当月的第一天。 关于ruby-如何每月在Heroku运行一次Scheduler插件?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/8692687/
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为