我正在使用画布制作一个基本的Web应用程序,在窗口调整大小时动态更改画布大小.我已经让它静态工作没有任何缺陷但是当我创建一个对象来动态地使它时它会抛出一个错误
在chrome中错误是:
未捕获的TypeError:对象[object Object]没有方法'getContext'
在Firefox中它是:
this.element.getContext不是函数
我在网上搜索过,这似乎是一个常见的问题,但没有一个提到的修复有任何区别.
该代码有问题如下:
layer['background'] = new canvasLayer("body","background");
function canvasLayer(location,id){
$(location).append("<canvas id='"+id+"'>unsupported browser</canvas>");
this.element=$(id);
this.context = this.element.getContext("2d"); //this is the line that throws the error
this.width=$(window).width(); //change the canvas size
this.height=$(window).height();
$(id).width($(window).width()); //change the canvas tag size to maintain proper scale
$(id).height($(window).height());
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我正在设计一个使用MongoDB安全存储私人信息的webapp.我想加密整个数据库,但看起来它不支持.我可以采取哪些路线来加密我的数据库?
我正在使用手机间隙开发一个IOS应用程序,我想使用node.js作为其中的一部分.获取phonegap是否可以在应用程序的其余部分运行node.js的实例?
我使用mongoosejs和node更新多个记录时遇到问题.出于某种原因,我只更新单个记录,即使多个匹配.我也注意到回调不会在.update()之后触发.我没有收到任何错误消息.这里发生了什么?
Page.find({status:'queued'})
.limit(queue_limit-queue.length)
.update({ status: 'active' },{ multi: true },function(err,num){
console.log("updated "+num);
//this callback will never fire, but a single record will be updated and marked as active.
});
Run Code Online (Sandbox Code Playgroud) 我有一个Vue组件,它有一个自定义的渲染方法.然而,该方法没有被调用.
<template>
<div class="guide"></div>
</template>
<script>
export default {
name: 'guide',
render: function(createElement){
return createElement('div', 'this will never get called?'),
},
};
</script>
Run Code Online (Sandbox Code Playgroud)
我查看了单个文件组件的文档,但没有提及有关render()的任何警告.还有另一种方法可以调用此方法吗?
我正在尝试创建一个自定义小部件但是当我提交时,Drupal似乎没有保存任何数据.当hook_field_attach_submit()
用于显示我粘贴的数据时,它被列为null.
奇怪的是,如果我将其更改#type
为单个文本字段而不是字段集,则它将仅保存已输入的字符串的第一个字符.
这似乎是一个验证问题,但我不确定如何挂钩或调试问题.我在哪里可以离开?
<?php
function guide_field_widget_info(){
dpm("guide_field_widget_info");
return array(
'guide_text_textfield' => array(
'label' => t('test Text field'),
'field types' => array('text'),
'settings' => array('size' => 60),
'behaviors' => array(
'multiple values' => FIELD_BEHAVIOR_CUSTOM,
'default value' => FIELD_BEHAVIOR_DEFAULT,
),
)
);
}
function guide_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
$field_name = $instance['field_name'];
$required = $element['#required'];
$item =& $items[$delta];
$element += array(
'#type' => 'fieldset',
'#title' => t('helloooooooo'),
);
$required = $element['#required'];
$item =& $items[$delta]; …
Run Code Online (Sandbox Code Playgroud) 我正在开发需要与Google进行身份验证的节点应用程序。当我请求令牌时,https://accounts.google.com/o/oauth2/token会回复:
error: 400
{
"error" : "invalid_request"
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试过在curl中发出相同的请求,并且收到了相同的错误,所以我怀疑我的请求有问题,但是我不知道是什么。我在下面粘贴了我的代码:
var request = require('request');
var token_request='code='+req['query']['code']+
'&client_id={client id}'+
'&client_secret={client secret}'+
'&redirect_uri=http%3A%2F%2Fmassiveboom.com:3000'+
'&grant_type=authorization_code';
request(
{ method: 'POST',
uri:'https://accounts.google.com/o/oauth2/token',
body: token_request
},
function (error, response, body) {
if(response.statusCode == 201){
console.log('document fetched');
console.log(body);
} else {
console.log('error: '+ response.statusCode);
console.log(body);
}
});
Run Code Online (Sandbox Code Playgroud)
我已三重检查以确保我提交的所有数据都是正确的,并且仍然出现相同的错误。我该怎么做才能进一步调试呢?
我正在制作一个 chrome 扩展,它在用户登录时设置一个 cookie。当我尝试使用该chrome.cookies.get()
方法读取 cookie 时,回调可以记录结果,但我无法将其从回调中传递出去。
function getCookie (cookieName){
var returnVal;
chrome.cookies.get({
'url':'https://addictedtogether.com/',
'name':cookieName
},
function(data){
console.log(data); //log displays returned cookie in a object
returnVal=data;
}
);
console.log(returnVal); //log says this is undefined
return returnVal;
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用几种不同的方式来传递结果,但似乎对象是未定义的,除非它是从回调中调用的。
我试图用它.on()
来告诉我在区域内点击了什么.为了捕获我点击的确切元素,我正在呼吁event.stopPropagation()
保持它不冒泡,但我的输出总是#containerDiv
及其内容.
我怎样才能确切地看到内部点击了#containerDiv
什么?代码段如下:
$("#containerDiv").on("click",function(event){
event.stopPropagation();
console.log($(this));
});
Run Code Online (Sandbox Code Playgroud) 我正在开发一个用Objective C编写的iOS应用程序,它有一个用Swift编写的附加类.当我尝试在我的Obj C AppDelegate.m中调用一个时,我没有收到任何错误,但回复回调永远不会触发.
我的ObjC有以下方法:
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply {
NSString *success =[ApiController handleCall];
//NSString *success =[self hello]; // This works if you swap it with the above method
//NSString *success = @"hello"; // when uncommented this also works.
NSDictionary *dict = @{@"status" : success};
reply(dict);
}
-(NSString *)hello{
return @"hello";
}
Run Code Online (Sandbox Code Playgroud)
NSString *success = [SwiftClass swiftMethod];
我的快速课程看起来像这样:
@objc class SwiftClass {
@objc func swiftMethod()->NSString{
return "it works!"
}
}
Run Code Online (Sandbox Code Playgroud)
除了上面的代码之外,我还确保包含#import "ProjectName-Swift.h"
,以及为swift代码创建桥接头.
我错过了什么吗?
javascript ×4
node.js ×3
html5 ×2
ios ×2
jquery ×2
mongodb ×2
canvas ×1
cookies ×1
cordova ×1
drupal ×1
drupal-7 ×1
encryption ×1
google-api ×1
mongoose ×1
nosql ×1
oauth ×1
oauth-2.0 ×1
objective-c ×1
security ×1
swift ×1
vue-router ×1
vue.js ×1