我想WebApi通过Ajax请求从控制器向Html页面发送一个对象.
当我在JS中收到对象时,它是空的.但是服务器端的对象不是空的,因为当我看到byte[].length它大于0时.
JS方面,我使用的是ProtobufJS库.这是我的.proto档案:
syntax="proto3";
message Container {
repeated TestModel2 Models = 1;
}
message TestModel2 {
string Property1 = 1;
bool Property2 = 2;
double Property3 = 3;
}
Run Code Online (Sandbox Code Playgroud)
服务器代码:
var container = new Container();
var model = new TestModel2
{
Property1 = "Test",
Property2 = true,
Property3 = 3.14
};
Run Code Online (Sandbox Code Playgroud)
container.Models.Add(模型);
Base64数据:
ChEKBFRlc3QQARkfhetRuB4JQA ==
JS解码:
var ProtoBuf = dcodeIO.ProtoBuf;
var xhr = ProtoBuf.Util.XHR();
xhr.open( …Run Code Online (Sandbox Code Playgroud)我正在学习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/
我正在从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)