我正在使用Angular,我在做一些我通常使用jQuery的东西时遇到了麻烦.
我想将click事件绑定到一个元素,然后单击,向下和向上滑动一个兄弟元素.
这就是jQuery的样子:
$('element').click(function() {
$(this).siblings('element').slideToggle();
});
Run Code Online (Sandbox Code Playgroud)
使用Angular我在我的标记中添加了一个带有函数的ng-click属性:
<div ng-click="events.displaySibling()"></div>
Run Code Online (Sandbox Code Playgroud)
这就是我的控制器的样子:
app.controller('myController', ['$scope', function($scope) {
$scope.events = {};
$scope.events.displaySibling = function() {
console.log('clicked');
}
}]);
Run Code Online (Sandbox Code Playgroud)
到目前为止,这是按预期工作,但我不知道如何完成幻灯片.很感谢任何形式的帮助.
我用指令取代了我所拥有的东西.
我的标记现在看起来像这样:
<div class="wrapper padding myevent"></div>
Run Code Online (Sandbox Code Playgroud)
我删除了控制器中的内容并创建了新指令.
app.directive('myevent', function() {
return {
restrict: 'C',
link: function(scope, element, attrs) {
element.bind('click', function($event) {
element.parent().children('ul').slideToggle();
});
}
}
});
Run Code Online (Sandbox Code Playgroud)
但是,我仍然无法让幻灯片切换工作.我不相信Angular支持slideToggle().有什么建议?
我有一个表格('#registrations'),我正在与Parsley.js验证,到目前为止它工作正常.但是,我正在尝试动态删除表单字段并将新的字段添加到Parsley验证中,具体取决于某人在选择下拉列表中选择的内容('#manureurer').
这是我的标记:
<select name="manufacturer" id="manufacturer" parsley-required="true" data-error-message="Please select a manufacturer.">
<option value="apple">Apple</option>
<option value="blackberry">Blackberry</option>
<option value="htc">HTC</option>
<option value="huawei">Huawei</option>
<option value="lg">LG</option>
<option value="motorola">Motorola</option>
<option value="nokia">Nokia</option>
<option value="samsung">Samsung</option>
<option value="sony">Sony</option>
<option value="sony-ericsson">Sony Ericsson</option>
</select>
Run Code Online (Sandbox Code Playgroud)
这是我的JS:
//init parsley
$('#registrations').parsley();
$('#manufacturer').change(function() {
//define selected value
var manufacturer = $(this).val();
//destroy parsley
$('#registrations').parsley('destroy');
//remove all models selects from parsley validation
//if someone has previously selected a different manufacturer
$('#registrations').parsley('removeItem', '#apple-models');
$('#registrations').parsley('removeItem', '#blackberry-models');
$('#registrations').parsley('removeItem', '#htc-models');
$('#registrations').parsley('removeItem', '#huawei-models');
$('#registrations').parsley('removeItem', '#lg-models');
$('#registrations').parsley('removeItem', '#motorola-models');
$('#registrations').parsley('removeItem', '#nokia-models');
$('#registrations').parsley('removeItem', '#samsung-models');
$('#registrations').parsley('removeItem', …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用error_log()我正在构建的自定义Wordpress插件,但出于某种原因,我不能.
当我使用error_log()我的网站时,我只是休息,但我没有看到任何错误debug.log.
我在我的wp_config.php文件中设置调试如下:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
Run Code Online (Sandbox Code Playgroud)
Stranegly,如果我error_log()在我的主题中使用,该网站不会破坏,但也没有任何输出debug.log.
我需要做什么才能error_log()在我的Wordpress插件和主题中使用?
我正在使用Wordpress 3.9.1.
根据这个答案,这个功能应该内置在Atom中,我应该可以customFileTypes用来完成这个.这就是我的配置:
"*":
"exception-reporting":
userId: ""
welcome:
showOnStartup: false
core:
themes: [
"atom-light-ui"
"atom-light-syntax"
]
customFileTypes:
"source.twig": [
"html"
]
editor:
invisibles: {}
tabLength: 4
showIndentGuide: true
showInvisibles: true
Run Code Online (Sandbox Code Playgroud)
请注意,我已经删除了我userId的安全值,但我确实在我的实际配置中有它.
奇怪的是,如果我改变了customFileTypeswith 的顺序themes,我的主题就会破碎.这是为什么?
更重要的是,如何设置所有.twig文件使用HTML(或HTML Moustache?)语法高亮?
我有一个SVG,其中包含数百个<circle>要附加click事件的元素。使用jQuery,这真的很容易:
$('circle').on('click', function(e) {
alert('clicked');
});
Run Code Online (Sandbox Code Playgroud)
我该如何在React中做到这一点?
通常,我将事件监听器直接附加到元素:
<circle onClick={(e) => handleClick()} />
看到有数百个元素,这将非常繁琐。有没有办法将单个事件侦听器附加到所有圈子元素?
我的工作解决方案使用香草JS,但是它涉及直接与DOM交互:
useEffect(() => {
const circles = document.querySelectorAll('circle');
for (const trigger of circles) {
trigger.addEventListener('click', (e) => {
alert('clicked');
});
}
}, []);
Run Code Online (Sandbox Code Playgroud)
我没有任何错误,这确实可行,但是感觉不像React。我想念什么吗?有没有更好的方法?
我有一个Ember应用程序,我正在使用一个动作来应用CSS动画.一旦动画完成,我想将操作从控制器冒泡到我的路线以处理更多功能.
我知道如果我return: true;的动作会冒出来,就像这里所解释的那样.
这就是我的控制器的样子:
App.MyController = Ember.ObjectController.extend({
actions: {
myAction: function() {
$('.my-element').addClass('my-animation-class').one('webkitAnimationEnd oanimationend msAnimationEnd animationend', function(e) {
console.log('working');
return true;
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
如果我在animationend回调中将某些内容记录到我的控制台,我可以看到它正常工作,如果我移出return: true;回调,则该动作会成功冒泡.但是,在回调内部返回true是行不通的.
我错过了什么?
我正在尝试将关联数组发送到我包含的Twig模板中:
{% include 'my-template.twig' with {
items: [
[
'property' => 'value',
'other' => 'value'
],
[
'property' => 'value',
'other' => 'value'
]
]
} %}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
PHP Fatal error: Uncaught exception 'Twig_Error_Syntax' with message 'An array element must be followed by a comma. Unexpected token "operator" of value "=" ("punctuation" expected with value ",")
它似乎不喜欢=>.这是我的语法吗?有没有办法实现这个目标?
我想使用HTML5 GeoLocation API来检索我的经度和纬度,并使用jQuery Deferred对象管理请求.
这是我的代码的样子:
var geoLocation = {
getLocation: function() {
// create deferred object
var deferred = $.Deferred();
// if geo location is supported
if(navigator.geolocation) {
// get current position and pass the results to this.geoLocationSuccess or time out after 5 seconds if it fails
navigator.geolocation.getCurrentPosition(this.geoLocationSuccess, this.geoLocationError, {
timeout: 5000
});
} else {
// geo location isn't supported
console.log('Your browser does not support Geo Location.');
}
},
geoLocationSuccess: function(position) {
// resolve deffered object
deferred.resolve(position.coords.latitude, position.coords.longitude);
// …Run Code Online (Sandbox Code Playgroud) 使用jQuery,我试图获取一些存在于远程HTML文件中的文本.
我正在使用带有"复制"类的filter()来指定我想要获取的远程文件中的文本.
这是我的代码:
$.get('/article.html', function(data) {
console.log($(data).filter('.copy').text());
});
Run Code Online (Sandbox Code Playgroud)
如果具有"copy"类的元素没有父元素,这似乎有效.但是,如果元素具有父元素,则无法获取文本.这是为什么?如果元素有父元素,有没有办法过滤响应?
我想使用Instagram API在我自己的网站上显示我自己的内容.我可以在他们的文档中看到,当应用程序处于沙盒模式时,内容所有者可以在其网站上显示多达20个媒体.
我在我的帐户上创建了一个应用程序,我正在尝试使用他们的客户端隐式身份验证来生成一个access_token.
我点击此网址并登录我的帐户:
https://www.instagram.com/oauth/authorize/?client_id=MYCLIENTID&redirect_uri=www.mysite.com&response_type=token
当我提交登录表单时,我被带到Instagram 404页面,上面写着:
Sorry, this page isn't available. The link you followed may be broken, or the page may have been removed. Go back to Instagram.
我错过了什么?我甚至需要access_token吗?在去年11月他们改变他们的API之前,我能够client_id在我的请求中使用它.我想那不可能了?
jquery ×3
php ×2
twig ×2
access-token ×1
angularjs ×1
atom-editor ×1
behavior ×1
bind ×1
callback ×1
color-coding ×1
controller ×1
debugging ×1
deferred ×1
dynamic ×1
ember.js ×1
events ×1
filter ×1
geolocation ×1
get ×1
html ×1
include ×1
instagram ×1
javascript ×1
parsley.js ×1
promise ×1
reactjs ×1
return ×1
slide ×1
syntax ×1
token ×1
validation ×1
wordpress ×1