service.js
.factory('EventService', function ($http, $cordovaSQLite) {
return {
//some code here..
populateData: function (data) {
var items = [];
for (i = 0; i < data.length; i++) {
items.push(data[i]);
}
return items;
}
}
})
Run Code Online (Sandbox Code Playgroud)
controller.js
.controller('NearCtrl', function ($scope, $http, $cordovaSQLite, EventService) {
EventService.getDataFromDB().then(function (result) {
if (result.length > 0) {
EventService.populateData(result).then(function (items) {
$scope.items = items;
})
} else {
EventService.getDataFromApi().then(function () {
EventService.getDataFromDB().then(function (result) {
EventService.populateData(result).then(function (items) {
$scope.items = items;
})
})
})
}
});
})
Run Code Online (Sandbox Code Playgroud)
当我尝试运行此代码时,我得到"TypeError:EventService.populateData(...).然后不是函数". …
任务是使用类似PowerPoint的d3旋转图形:
得到了这个示例,试图实现相同的行为。无法理解,错误出在哪里-人物在晃动,没有按照应有的方式旋转。
function dragPointRotate(rotateHandleStartPos) {
rotateHandleStartPos.x += d3.event.dx;
rotateHandleStartPos.y += d3.event.dy;
const updatedRotateCoordinates = r
// calculates the difference between the current mouse position and the center line
var angleFinal = calcAngleDeg(
updatedRotateCoordinates,
rotateHandleStartPos
);
// gets the difference of the angles to get to the final angle
var angle =
rotateHandleStartPos.angle +
angleFinal -
rotateHandleStartPos.iniAngle;
// converts the values to stay inside the 360 positive
angle %= 360;
if (angle < 0) {
angle += 360;
} …Run Code Online (Sandbox Code Playgroud) 码:
function deleteItem(req, res) {
Goods.findByIdAndRemove(req.params.id, (err) => {
if (err) {
res.send({
success: false,
error: err
});
} else {
res.send({
success: true,
item: req.params.id
});
}
})
}
Run Code Online (Sandbox Code Playgroud)
如果我传递一个_id刚刚删除的文件 - Mongoose成功"删除"它.
如果我传递一个_id从未存在过的文件,比如591dad9a1583ea0d1065d633- 它也会"删除"它.
只有在传递垃圾时才会抛出错误a34pnv530eargdzbs.
有人可以告诉我,发生了什么事,拜托?:)
我有一个表单,可以应用不同的验证,具体取决于action存储在 VUEX 存储中的参数。我试试这个:
data: function() {
const validations = {
sendToProject: {
cardProject: {
required,
},
},
recallToBranch: {
fioReceiver: {
required,
}
}
}
return {
validations,
}
},
validations() {
return {
q: this.validations[this.action] // supposed to be this.validations['sendToProject']
}
},
computed: {
...mapGetters({
action: 'action',
}),
},
Run Code Online (Sandbox Code Playgroud)
这实际上有效,但在引导时抛出错误:
[Vue warn]: Error in render function: "TypeError: can't convert undefined to object"
并且该错误阻止了非 Vue 代码(Bootstrap jQuery 插件初始化等)的执行。
怎么修?谢谢。