小编ale*_*mac的帖子

Javascript和Knockout

我是Javascript和Knockout的新手.我坚持要绑定我的ViewModal.以下是ViewModal和View在同一个Index.chtml文件中时正在运行的代码:

ProfilesViewModel = function () {
    self = this;
    self.ProfileId = ko.observable("");
    self.FirstName = ko.observable("");
    self.LastName = ko.observable("");
    self.Email = ko.observable("");
    self.Image = ko.observable("");
    self.Phone = ko.observable("");

    // Public data properties
    self.Profiles = ko.observableArray([]);

    GetAllProfiles();

    function GetAllProfiles() {
        //  alert("here");
        $.ajax({
            type: "get",
            url: "@Url.Action("getAllProfiles")",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
               self.Profiles(data); //Put the response in ObservableArray
            },
            error: function (error) {
               alert(error.status + "<--and--> " + error.statusText);
            }
        });
    };
}
Run Code Online (Sandbox Code Playgroud)

但当我将我的ViewModal移动到另一个Js文件时,如下 Modal.js代码: …

javascript asp.net-mvc binding knockout.js

1
推荐指数
1
解决办法
221
查看次数

Node.js 依赖安装提供“证书链中的自签名证书”

我正在尝试安装依赖ursa包。但我收到此错误:

self signed certificate in certificate chain
Run Code Online (Sandbox Code Playgroud)

关于如何解决这个问题的任何想法?

我已经设置了正确的代理设置,并且能够下载“node-horseman”依赖项。

任何输入将不胜感激。提前致谢。

>node --version
v6.9.1
>npm install ursa
...\node_modules\ursa>if not defined npm_config_node_gyp (node "C:\Users
\xxxxxxxxxxx\AppData\Roaming\npm\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "" rebuild )
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: self signed certificate in certificate chain
gyp ERR! stack     at Error (native)
gyp ERR! stack     at TLSSocket.<anonymous> (_tls_wrap.js:1062:38)
gyp ERR! stack     at emitNone (events.js:86:13)
gyp ERR! stack     at TLSSocket.emit (events.js:185:7)
gyp …
Run Code Online (Sandbox Code Playgroud)

ssl certificate node.js npm

1
推荐指数
1
解决办法
2251
查看次数

JavaScript 新 Promise 简写

我想知道是否有任何简写可以在 JavaScript 中创建 Promise,或者有什么方法可以将 .then 添加到普通函数中。例子:

dbl = a => a | 0 ? a * 2 : !1;
dbl(10).then(r => r / 2); // should be original number entered.
Run Code Online (Sandbox Code Playgroud)

我想让 dbl 函数成为一个承诺,但保持相当短。或者向函数添加某种原型,让我可以执行类似于上面代码的操作。

javascript function promise es6-promise

1
推荐指数
1
解决办法
2328
查看次数

删除属性在 node.js 中不起作用

我想知道为什么我不能删除密码对象,我的控制台结果显示密码仍然存在,我想知道为什么。

User.comparePassword(password, user.password , (err, result) => {
  if (result === true){
    User.getUserById(user._id, (err, userResult) => {
      delete userResult.password

      const secret = config.secret;
      const token = jwt.encode(userResult, secret);

      console.log(userResult)

      res.json({success: true, msg: {token}});
    });
  } else {
    res.json({success: false, msg: 'Error, Incorrect password!'});
  }
}
Run Code Online (Sandbox Code Playgroud)

javascript node.js express ecmascript-6

1
推荐指数
1
解决办法
1187
查看次数

使用async等待的REST API调用

这是我的代码片段

var clients = require('restify-clients');

async function callApi(val){
        const client = clients.createJsonClient({ url: apiUrl });
        await client.get('/my/url', (err, req, res, obj) => {
            if (err) {
                return err;
            } else {
                return obj;
            }
        });
}
Run Code Online (Sandbox Code Playgroud)

我尝试了几种方法来调用它,但它们都没有用

第一种方式:

var results = await callApi(val);
Run Code Online (Sandbox Code Playgroud)

第二种方式:

var results = callApi(val).then(data => {
                console.log(data);
            })
Run Code Online (Sandbox Code Playgroud)

javascript node.js promise async-await

1
推荐指数
1
解决办法
2505
查看次数

已成功安装Node.js!哦,但为什么这段代码没有渲染?

输出是

{$questions[i]}
Run Code Online (Sandbox Code Playgroud)

它没有提出我的第一个问题!

这是代码:

var questions = [
  "What is your name?",
  "What is your favorite fruit?",
  "What is the meaning of life?"
];
var answers = [];

function ask(i){
    process.stdout.write(`\n\n {$questions[i]} \n\n `);
    process.stdout.write(" > ");
}

ask(0);
Run Code Online (Sandbox Code Playgroud)

我错过了什么?

javascript node.js

0
推荐指数
1
解决办法
47
查看次数