我正在使用nodejs的loopback框架.
是否可以一次连接多个数据库.
例如,我有两个不同的数据库.
1. Mysql Database - A
2. Postgresql - B
Run Code Online (Sandbox Code Playgroud)
有些页面从A数据库获取数据,有些页面需要从B数据库获取数据.有可能这样做吗?
更多细节:
假设我们有两个模块.一个模块与MySQL交互,另一个模块与postgreSQL交互.
我在单个函数(abcd)中使用回调嵌套了内部函数.
我需要使用异步从外部调用abcd函数并返回响应.
var listFunctions = {
test1 : function(objectData, callbackData) {
//have logic and retrun data
callbackData(null, "a");
},
test2 : function(objectData, callbackData) {
//have logic and retrun data
callbackData(null, "b");
},
test3 : function(objectData, callbackData) {
//have logic and retrun data
callbackData(null, "c");
},
test4 : function(objectData, callbackData) {
//have logic and retrun data
callbackData(null, "d");
},
test5 : function(objectData, callbackData) {
//have logic and retrun data
callbackData(null, "e");
}
};
function abcd(objectData, clb) {
listFunctions.test1(objectData, function(err, data1) { …
Run Code Online (Sandbox Code Playgroud) 我有这样的表:
表格1:
<table>
<tr>
<th>Title1</th>
<th>Title2</th>
<th>Title3</th>
<th>Title4</th>
</tr>
<tr>
<td>Text1</td>
<td>Text2</td>
<td>Text3</td>
<td>Text4</td>
</tr>
<tr>
<td>Text1</td>
<td>Text2</td>
<td>Text3</td>
<td>Text4</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
表2:
<table>
<tr>
<th>Title1</th>
<th>Title2</th>
<th>Title4</th>
</tr>
<tr>
<td>Text1</td>
<td>Text2</td>
<td>Text4</td>
</tr>
<tr>
<td>Text1</td>
<td>Text2</td>
<td>Text4</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
表3:
<table>
<tr>
<th>Title4</th>
</tr>
<tr>
<td>Text4</td>
</tr>
<tr>
<td>Text4</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
这里我有3个表(3个表不是常量.但是所有表都有Title4标题但位置不同.我需要更改文本"Title4"的所有表的颜色,而不使用jquery/javascript.仅在css中使用.任何建议?
我是AngularJS的新手,我正在尝试根据表tr和td值制作格式化的JSON.
表tr是自动生成的.提交表单后,我尝试生成json值.
提交表单后,我需要生成JSON.
<form>
<table>
<!-- Auto generated rows -->
<tr>
<td>
<input type="text" class="form-control" name="tname" value="">
</td>
<td>
<select ng-model="selection1" class="form-control" name="ttype" value="">
<option value="bbb" selected>Test</option>
<option value="aaa" >Lumpsum</option>
</select></td>
<input type="text" class="form-control parsley-success" name="tvalue" >
</td>
</tr>
<tr>
<td>
<input type="text" class="form-control" name="tname" value="">
</td>
<td>
<select ng-model="selection1" class="form-control" name="ttype" value="">
<option value="bbb" selected>Test</option>
<option value="aaa" >Lumpsum</option>
</select></td>
<input type="text" class="form-control parsley-success" name="tvalue" >
</td>
</tr>
<tr>
<td>
<input type="text" class="form-control" name="tname" value="">
</td>
<td>
<select ng-model="selection1" class="form-control" …
Run Code Online (Sandbox Code Playgroud) 我正在使用jquery.pagination.js
插件.
我有100页.第一页和最后一页是数字显示,但没有显示点.请检查屏幕截图和代码.
$("#Pagination").pagination(num_entries, {
items_per_page : 10,
num_display_entries : 2,
num_edge_entries : 1,
current_page : pageIndex-1,
//link_to : path +"?"+param
callback : paginationCallback
});
function paginationCallback(page_index, jq) {
}
Run Code Online (Sandbox Code Playgroud)
是否有用于显示点符号的默认选项?
我需要使用javascript基于键值合并两个json对象.
我有两个不同的变量g和c.
术语:所有值都需要合并.
var g = [ { id: 36, name: 'AAA', goal: 'yes' },
{ id: 40, name: 'BBB', goal: 'yes' },
{ id: 57, name: 'CCC', goal: 'yes' },
{ id: 4, name: 'DDD', goal: 'yes' },
{ id: 39, name: 'EEE', goal: 'yes' },
{ id: 37, name: 'FFF', goal: 'yes' },
{ id: 59, name: 'GGG', goal: 'yes' },
{ id: 50, name: 'III', goal: 'yes' },
{ id: 43, name: 'HHH', goal: 'yes' },
{ …
Run Code Online (Sandbox Code Playgroud) 我正在关注该文件以下载该文件.
https://docs.strongloop.com/display/public/LB/Storage+component
在该文档中,如果下载文件意味着需要遵循url模式.
GET/containers/{container}/files/{file}
例:
我有容器1(容器名称)和文件名lb.png.
所以我像这样制作了网址
http://localhost:3000/api/containers/container1/files/lb.png?access_token=8Hfay0LRU2g22BjCqf3q8HsQCdsVBgBp9MHeekr3LfNLlILVUzUHUsUKOZmjTRD9
Run Code Online (Sandbox Code Playgroud)
我收到了文件名的响应,我希望一旦我在浏览器中使用url意味着该文件应该下载到url中.
得到的回应:
{
"container": "container1",
"name": "lb.png",
"size": 38780,
"atime": "2016-03-18T05:13:41.000Z",
"mtime": "2016-03-18T05:09:06.000Z",
"ctime": "2016-03-18T05:09:06.000Z"
}
Run Code Online (Sandbox Code Playgroud)
预期产出:
我需要下载文件(lb.png).
我有两个数组对象(arrayList1,arrayList2)。我只是想将这两个数组合并为一个数组对象。我使用了以下术语。
有人可以简化我的代码吗..
注意 :
const arrayList1 = [
{ type: "A", any: 11, other: "ab", props: "1" },
{ type: "B", any: 22, other: "bc", props: "2" }, // same type
{ type: "C", any: 33, other: "df", props: "3" }
];
const arrayList2 = [
{ type: "D", any: 44, other: "aa", props: "11" },
{ type: "B", any: 22, other: "bb", props: "2----2" , x: 10}, // same type …
Run Code Online (Sandbox Code Playgroud)您好,我正在使用d3.js条形图.我想显示特定栏的箭头和文字.我附上了图片和代码.
var dataset = [{ "keyword": "0-10", "global": 500, }, { "keyword": "11-20", "global": 300, }, { "keyword": "21-30", "global": 90, }, { "keyword": "31-40", "global": 400, }, { "keyword": "41-50", "global": 600, }, { "keyword": "51-60", "global": 100, }, { "keyword": "61-70", "global": 560, }, { "keyword": "71-80", "global": 256, }, { "keyword": "81-90", "global": 198, }, { "keyword": "91-100", "global": 233, }];
Graph(dataset);
function Graph(input) {
var margin = {
top: 15,
right: 10,
bottom: 60,
left: 60 …
Run Code Online (Sandbox Code Playgroud) 我正在使用节点js和nodemon模块.
问题:如果我在前端更改文件,服务器将自动重启.
预期:如果我更改路径中的几个js或几个文件,它不应该重新启动服务器.
我尝试了以下代码:
nodemon --ignore'public/javascripts/template_files/*.js'
但上面的代码不起作用.如果我更改template_files文件夹中的任何js文件意味着服务器一次又一次地重新启动.
我有这样的示例代码:
html代码:
<body ng-controller="MainCtrl">
<form name="myForm">
<input name="myText" type="text" name="test" ng-model="mytext" required />
<button ng-click="save()" ng-disabled="myForm.$invalid">Save</button>
</form>
</body>
Run Code Online (Sandbox Code Playgroud)
JS代码:
var app = angular.module('angularjs-starter', []);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
$scope.save = function(){
//logic or http method
console.log("Test");
}
});
Run Code Online (Sandbox Code Playgroud)
在此链接中附上代码:单击此处
逻辑:
注意:这里我只附加了一个输入,但我有多个输入字段。另外,在保存功能中,我将逻辑数据保存到数据库中。
我正在使用angularjs,在后端我检查每个api身份验证.每个请求都应该检查参数access_token.
$provide.factory('MyHttpInterceptor', function($q, $location, $localStorage) {
return {
request : function(config) {
config.params = config.params || {};
if ($localStorage.access_token) {
config.params.access_token = $localStorage.access_token;
}
return config || $q.when(config);
},
};
});
// Add the interceptor to the $httpProvider.
$httpProvider.interceptors.push('MyHttpInterceptor');
Run Code Online (Sandbox Code Playgroud)
我用这个代码.它工作得很好,但我在开发工具(网络)中看到html,css,js文件也添加了参数.喜欢.
http://localhost/webapp/views/template/left-menu.html?access_token=xxxxxxxxxxxxxxxxx
http://localhost/webapp/css/index.css?access_token=xxxxxxxxxxxxxxxxx
Run Code Online (Sandbox Code Playgroud)
但我不喜欢将access_token发送到所有http请求(html,css,js).
我喜欢发送带有前缀api的access_token
http://localhost:9090/api/user/get?access_token=xxxxxxxxxxxxxxxxxxxxxx
//I think the solution is find the http url and grep the text api, if found means add the parameter. Don't konw this is good approach.
Please me the good approach.
Run Code Online (Sandbox Code Playgroud)
我只期望只有后端api请求.另外,我不希望每个严格的http请求添加参数.
可以在config中添加常见的一个位置吗?
我有嵌套数组列表的列表,我正在尝试根据数组值进行调整。当我过滤时出现错误。我正在使用带有 eslint 的打字稿。
Argument of type 'string | undefined' is not assignable to parameter of type 'string'
Run Code Online (Sandbox Code Playgroud)
但我检查了空/未定义值,但仍然收到错误。
interface User {
id: string;
username?: string;
}
function getList (user:User){
if(user.username === undefined){
return {};
}
let arrayData: string[][] = [];
arrayData = [["abcd"],["efgh"],["xyz"],["abcd","xyz"]];
//here i have differnt logic
const filterData = arrayData.filter(list => list.includes(user.username));
return filterData;
}
getList({id: "123", username: "xyz"});
Run Code Online (Sandbox Code Playgroud)
当我使用non-null assertion operator
它时,错误已解决,但出现了 lint 问题。
const filterData = arrayData.filter(list => list.includes(user.username!));
Run Code Online (Sandbox Code Playgroud)
谁能帮我解决这个问题。
javascript ×8
node.js ×5
angularjs ×3
jquery ×2
json ×2
loopbackjs ×2
strongloop ×2
arrays ×1
asynchronous ×1
callback ×1
css ×1
d3.js ×1
download ×1
eslint ×1
factory ×1
html ×1
http ×1
interceptor ×1
mysql ×1
node-async ×1
nodemon ×1
object ×1
postgresql ×1
svg ×1
typescript ×1
validation ×1