小编Gui*_*ume的帖子

Protobuf:WebApi - > JS - 解码对象为空

我想WebApi通过Ajax请求从控制器向Html页面发送一个对象.

当我在JS中收到对象时,它是空的.但是服务器端的对象不是空的,因为当我看到byte[].length它大于0时.

javascript protocol-buffers asp.net-web-api protobuf.js

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

Knockout JS - 将类序列化为JSON

我正在学习Knockout JS(非常棒的框架!顺便说一句,我来自Silverlight,MVVM powa),我认为我阻止了一件简单的事情.

我有一个User这样的课:

var User = function () {
    this.Login = ko.observable();
    this.FirstName = ko.observable();
    this.LastName = ko.observable();
    this.Password = ko.observable();
    this.Email = ko.observable();
};
Run Code Online (Sandbox Code Playgroud)

像这样的ViewModel:

var UsersPage = function () {
    /*
    * Properties
    */
    this.self = this;
    this.users = ko.observableArray([new User()]);
    this.newUser = ko.observable(new User());

    /*
    * Methods
    */
    this.saveUser = function () {
        alert(ko.ToJSON(this.newUser()));
    };
};
Run Code Online (Sandbox Code Playgroud)

在HTML中,我有一个绑定到"newUser"属性的简单表单.当我提交表单时,我想在JSON中序列化属性以将其传递给WCF服务.这ko.ToJSON似乎不起作用.我尝试了几种方法,但我没有得到我期望的结果.

所以,我的问题是:如何将我的User属性序列化为JSON?

这是一个重现它的JSFiddle:http://jsfiddle.net/ZfSbR/5/

serialization json knockout.js

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

如何使用默认应用程序打开文件

我正在从DropBox下载文件.

我可以通过使用看到该文件存在File.exists(filePath)并返回true.但我无法使用File.fromPath(filePath)或使用任何一个打开文件(使用默认应用程序)openUrl(filePath).

这是我的代码:

HomePage.prototype.getDownload = function() {
var filePath = fs.path.join(fs.knownFolders.currentApp().path, "MyFile");

httpModule.getFile({
    url: "https://content.dropboxapi.com/2/files/download",
    method: "POST",
    headers: { "Content-Type": "", "Dropbox-API-Arg": JSON.stringify({"path": "/MyFolder/MyFile"}), "Authorization": "Bearer *********" },      
}, filePath).then(function (response) {
    console.log("file exists: "+fs.File.exists(filePath)); // This return true
    // tried this
    fs.File.fromPath(filePath); // Does nothing
    // tried this
    utilsutils.openUrl(filePath); // Does nothing
}
Run Code Online (Sandbox Code Playgroud)

nativescript

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