我正在尝试上传图像并使用下面的代码更新数据库集合中的图像的URL.
Controller.prototype.handle = function (req, res, next) {
var id = req.params.id,
controller = req.params.controller,
optionalController;
optionalController = _.clone(controller);
// handle optional controller
if (controller === 'newboat') {
controller = 'boat';
} else if (controller === 'newcrew') {
controller = 'crew';
}
var files = req.files.files || {},
monthYear = new Date(),
monthYear = [monthYear.getFullYear(), monthYear.getMonth()],
filename = files[0].originalFilename,
path = files[0].path,
extension = filename.match(EXPRESSION_EXTENSION)[1],
destFolder = [ROOT, monthYear[0], '/', monthYear[1] ].join(''),
destination = [ROOT, monthYear[0], '/', monthYear[1] ,'/', id, …Run Code Online (Sandbox Code Playgroud) 我一直使用summernote作为我的默认文本编辑器,但是在初始化时我默认无法设置特定的字体大小.
到目前为止我试过了
$('.active-textcontainer').summernote({
toolbar: [
['style', ['bold', 'italic', 'underline']],
['fontsize', ['fontsize']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']]
],
height:150,
fontsize:'18px'
});
Run Code Online (Sandbox Code Playgroud)
和
$('.active-textcontainer').summernote({
toolbar: [
['style', ['bold', 'italic', 'underline']],
['fontsize', ['fontsize']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']]
],
height:150,
fontsize:'18'
});
Run Code Online (Sandbox Code Playgroud)
蚂蚁帮助将不胜感激.
我想利用promises功能,我可以同步连接到mongodb,我可以通过将连接传递给不同的模块来重用连接.
这是我想出来的东西
class MongoDB {
constructor(db,collection) {
this.collection = db.collection(collection);
}
find(query, projection) {
if(projection)
return this.collection.find(query, projection);
else
return this.collection.find(query);
}
}
class Crew extends MongoDB {
constructor(db) {
super(db,'crews');
}
validate() {
}
}
Run Code Online (Sandbox Code Playgroud)
我想在我的初始代码中的某个位置设置一个连接,如下面的那个,然后重用不同类的连接,就像mongoose或monk那样,但只使用node-mongodb-native包.
MongoClient.connect(url)
.then( (err,dbase) => {
global.DB = dbase;
});
var Crew = new CrewModel(global.DB);
Crew.find({})
.then(function(resp) {
console.log(resp);
});
Run Code Online (Sandbox Code Playgroud)
现在,db在主MongoDB类中返回undefined,并且无法通过谷歌或文档调试这个.
编辑:我曾假设承诺是同步的但事实并非如此.
我是新来表达的,我很惊讶我应该如何访问前端的数据,
我有以下代码
exports.init = function(req, res){
if (req.isAuthenticated()) {
//res.send();
var userId = req.user._id
res.render('account/usernotes');
}
else {
res.render('signup/index', {
oauthMessage: '',
oauthTwitter: !!req.app.config.oauth.twitter.key,
oauthFacebook: !!req.app.config.oauth.facebook.key,
oauthGoogle: !!req.app.config.oauth.google.key
});
}
};
Run Code Online (Sandbox Code Playgroud)
我想将UserId发送到视图,以便我可以访问它,以便我可以使用它获取数据,但到目前为止使用send(); 将数据的值呈现给前端,因此如何访问它.我猜
res.render('account/usernotes',req.user._id);
Run Code Online (Sandbox Code Playgroud)
应该工作,但如何在此之后访问数据?
即使我提供了所有字段,我在保存到数据库时收到以下消息的验证错误,
{ [ValidationError: Validation failed]
message: 'Validation failed',
name: 'ValidationError',
errors:
{ Name:
{ [ValidatorError: Path `Name` is required.]
message: 'Path `Name` is required.',
name: 'ValidatorError',
path: 'Name',
type: 'required',
value: undefined } } }
Run Code Online (Sandbox Code Playgroud)
这就是我想要保存的对象的样子
{ Name: 'Nobody Singh',
phone: '+919177121364',
address: 'flat no 306 koratala apartments\nstreet no 3 ,Himayatnagar, Near Siraj plaza',
start: '2014-12-03T13:00:00.000Z',
end: '2014-12-03T15:00:00.000Z',
details: 'flat no 306 koratala apartments\nstreet no 3 ,Himayatnagar, Near Siraj plaza' }
Run Code Online (Sandbox Code Playgroud)
这是架构
// load the things we need
var mongoose …Run Code Online (Sandbox Code Playgroud) 我想在vuejs项目中使用bootstrap select插件,我对如何将它作为指令合并到我的项目中感到困惑.在查看vuejs网站中的select2示例后,我想出了以下内容.
<span id="el">
<select class="selectpicker" data-style="btn-primary" v-selectpicker="selected" :options="workflow">
<option value="0">default</option>
</select>
</span>
Run Code Online (Sandbox Code Playgroud)
这是我的指示和观点
require("bootstrap-select");
Vue.directive('selectpicker',{
twoWay: true,
deep: true,
bind: function() {
$(this.el).selectpicker().on("change", function(e) {
this.set($(this.el).val());
}.bind(this));
},
update: function (value) {
$(this.el).selectpicker('refresh').trigger("change");
},
unbind: function () {
$(this.el).off().selectpicker('destroy');
}
});
new Vue({
el: '#el',
data: {
tasksLoaded: false,
tasks: [],
workflow: [
{
id:'todo',
value: 'To Do'
},
{
id: 'backlog',
value: 'Backlog'
},
{
id: 'doing',
value: 'Doing'
},
{
id: 'restest',
value:'Retest'
},
{
id: 'completed', …Run Code Online (Sandbox Code Playgroud) 我有一个JSON对象,我想创建一个使用mongoose的模式
{ ProjectName: 'asdf',
Embargo: 'Yes',
Angle: '1',
Facts: '[{"count":1,"fact":"dsafdsaf","content":"dsafdsaf"}, {"count":3,"fact":"dsafdsaf","content":"dsafdsaf" } , {"count":2,"fact":"dsafdsaf","content":"dsafdsaf"}]',
About: '<p>Anthony Bodin </p>',
EditorNote: 'No',
OrderId: 'tok_14kGRO2Jju1nvjb47YF9jQTJ',
Payment: 'Paid' }
Run Code Online (Sandbox Code Playgroud)
我的问题是Facts元素将包含对象数组,我不太确定如何将它保存到数据库中,因为这是我现在拥有的模式
var ArticleSchema = new mongoose.Schema({
userId: {
type: String,
default: ''
},
userEmail: {
type: String,
default: ''
},
article: {
date: {
type: Date,
default: Date()
},
ProjectName: {
type: String,
default: ''
},
Embargo: {
type: String,
default: true
},
Angle: {
type: String,
default: ''
},
Facts: {
type:Array
},
About: { …Run Code Online (Sandbox Code Playgroud) 我在SpyOn方法上得到一个未定义的错误
这就是我想出的
'use strict';
describe('WebApp: AccountController', function() {
return beforeEach(function() {
module('webApp');
module('tpls');
return inject(function($injector) {
this.q = $injector.get('$q');
this.userMock = {
id: 1,
email: 'pidsafs@gmail.com',
name: 'Adones Pitogo'
};
this.modalMock = {
open: (function(_this) {
return function(tpl, ctrl) {
_this.def = _this.q.defer();
_this.def.resolve(true);
return {
result: _this.def.promise
};
};
})(this)
};
this.teamMock = {
id: 1
};
this.repoMock = {
id: 1
};
this.httpBackend = $injector.get('$httpBackend');
this.httpBackend.whenGET('/api/v1/session').respond({
status: 'ok',
user: this.userMock
});
this.httpBackend.whenGET("/api/v1/users/" + this.userMock.id + "/teams").respond({
status: 'ok', …Run Code Online (Sandbox Code Playgroud) 我是JSON的新手,我使用json_encode创建一个看起来像这样的JSON对象
[{
"timestamp": "12\/16\/2013 0:00",
"curr_property": "7211",
"curr_property_cost": "123",
"day_property": "48",
"day_property_cost": "281",
"curr_solar_generating": "4958",
"curr_solar_export": "0",
"day_solar_generated": "33",
"day_solar_export": "0",
"curr_chan1": "1964",
"curr_chan2": "4958",
"curr_chan3": "289",
"day_chan1": "13",
"day_chan2": "33",
"day_chan3": "1"
}, {
"timestamp": "12\/16\/2013 0:00",
"curr_property": "7179",
"curr_property_cost": "123",
"day_property": "72",
"day_property_cost": "281",
"curr_solar_generating": "4926",
"curr_solar_export": "0",
"day_solar_generated": "49",
"day_solar_export": "0",
"curr_chan1": "1980",
"curr_chan2": "4926",
"curr_chan3": "273",
"day_chan1": "19",
"day_chan2": "49",
"day_chan3": "2"
}, {
"timestamp": "12\/16\/2013 0:00",
"curr_property": "9627",
"curr_property_cost": "165",
"day_property": "104",
"day_property_cost": "282",
"curr_solar_generating": …Run Code Online (Sandbox Code Playgroud) 我有一个格式不正确的JSON响应,其中包含特殊字符,我想通过使用string.replace()删除特殊字符来清理它。由于某种原因,它不起作用。
这是JSON结果
[{"User::newPassword":["Password could not be changed. The request can't be validated"]},[]]
Run Code Online (Sandbox Code Playgroud)
这是我的表情。
resp.replace(::g, '');
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用。任何对此的建议将不胜感激,因为后端我对此无能为力。
我对我在代码中做错了什么感到有些困惑
function submitArticle() {
var postTitle = encodeURIComponent(document.getElementById('postTitle').value);
var postDes = encodeURIComponent(document.getElementById('postDes').value);
var postCont = encodeURIComponent(document.getElementById('postCont').value);
var data = "postTitle=" + postTitle + "&postDes=" + postDes + "&postCont=" + postDes;
var getXML = function () {
try {
xhr = new XMLHttpRequest();
}
catch(e) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e) {
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e) {
alert("Your Browser is not Supported");
}
}
}
}
open('POST', 'http://localhost/blog/engine/engine.php', true);
setRequestHeader("Content-type", "application/x-www-form-urlencoded");
send(data);
getXML.onreadystatechange = …Run Code Online (Sandbox Code Playgroud) javascript ×5
node.js ×5
express ×3
json ×3
mongodb ×3
ajax ×1
angularjs ×1
arrays ×1
asynchronous ×1
callback ×1
jasmine ×1
jquery ×1
karma-runner ×1
mongoose ×1
summernote ×1
unit-testing ×1
vue.js ×1