Jquery 将VS 2013 SPA模板从淘汰赛转换为剑道

Jquery 将VS 2013 SPA模板从淘汰赛转换为剑道,jquery,kendo-ui,requirejs,single-page-application,Jquery,Kendo Ui,Requirejs,Single Page Application,我正在关注剑道ui框架。我最初的尝试面临几个问题,我不知道如何解决它们。你的帮助将引导我更好地理解剑道: define(['kendo', 'security-dataservice', 'security-model', 'security-helper', 'security-authservice', 'router', 'ajaxPrefilters'], function (kendo, dataservice, model, helper, authservice, router)

我正在关注剑道ui框架。我最初的尝试面临几个问题,我不知道如何解决它们。你的帮助将引导我更好地理解剑道:

define(['kendo', 'security-dataservice', 'security-model', 'security-helper', 'security-authservice', 'router', 'ajaxPrefilters'],
function (kendo, dataservice, model, helper, authservice, router) {
    var userInfo = new kendo.data.ObservableObject({
        userName: "",
        password: "",
        rememberMe: false,
        loggingIn: false,
        errors: [],

        loadingExternalLogin: false,
        externalLoginProviders: [],
        hasExternalLogin: function () {
            return this.get("externalLoginProviders").length > 0;
        },
        login: function () {
            //var self = this;
            //if (typeof (this.get("userInfo.errors")) !== 'undefined')
                this.get("userInfo.errors").splice(0, this.get("userInfo.errors").length);

            this.set("userInfo.loggingIn", true); // THIS LINE IS WORKING PROPERLY WHILE INSIDE .done AND .failJSON NOT WORKING

            var name = this.get("userInfo.userName");
            var pass = this.get("userInfo.password");

            dataservice.login({
                grant_type: "password",
                UserName: name,
                Password: pass // Up to here the code is working correctly**
            }).done(function (data) {
                //this.set("userInfo.loggingIn", false); // << This line does not working with "uncaught TypeError"
                this.loggingIn = false; // Is this line correct?

                if (data.userName && data.access_token) {
                    authservice.logUserIn(data.userName, data.access_token, this.rememberMe);
                } else {
                    //this.get("errors").push("An unknown error occurred.");
                    userInfo.errors.push("An unknown error occurred.");
                }
            }).failJSON(function (data) {
                this.loggingIn = false;

                if (data && data.error_description) {
                    userInfo.errors.push(data.error_description);
                } else {
                    userInfo.errors.push("An unknown error occurred.");
                }
                //if (data && data.error_description) {
                //    this.get("errors").push(data.error_description);
                //} else {
                //    this.get("errors").push("An unknown error occurred.");
                //}
            });
        }
    });

    return {
        userInfo: userInfo
    }
});
define(['kendo','security dataservice','security model','security helper','security authservice','router','ajaxPrefilters'],
功能(剑道、数据服务、模型、助手、authservice、路由器){
var userInfo=new kendo.data.observeObject({
用户名:“”,
密码:“”,
记住:错,
登录:错误,
错误:[],
加载外部登录:false,
外部登录提供程序:[],
hasExternalLogin:函数(){
返回此.get(“externalLoginProviders”).length>0;
},
登录:函数(){
//var self=这个;
//if(typeof(this.get(“userInfo.errors”)!==“未定义”)
this.get(“userInfo.errors”).splice(0,this.get(“userInfo.errors”).length);
this.set(“userInfo.logging”,true);//在.done和.failJSON内部时,此行工作正常
var name=this.get(“userInfo.userName”);
var pass=this.get(“userInfo.password”);
dataservice.login({
授权类型:“密码”,
用户名:name,
密码:pass//转到此处代码工作正常**
}).完成(功能(数据){

//this.set(“userInfo.logging”,false);//此处的范围界定存在几个问题:

第一:应该是

this.set("loggingIn", true);
由于
在此上下文中是可观察的对象,您要设置的属性是
登录

然后,在传递给
done()
failJSON()
的函数中,您需要使用
userInfo.set()
而不是
this.set()
,因为显然数据服务正在为函数设置上下文:

var that = this;
dataservice.login({
    grant_type: "password",
    UserName: name,
    Password: pass // Up to here the code is working correctly**
}).done(function (data) {
    that.set("loggingIn", false); 
    // ...
})

这是几个不相关的问题;我建议为每个问题创建一个单独的问题。我建议继续使用Knockout.js,因为它有很多很棒的东西,但是有一个叫做Knockout-Kendo.js的东西,它通过结合Knockout和Kendo来工作。但是,如果你要移动,Knockout在Kendo移动框架中不起作用unately@LarsHöppner:很抱歉收集了几个问题,但我觉得它们都与剑道+JQuery、Ajax有关。我想知道如何将它们分为三个问题。@Ohjay44:谢谢你的参考,但我是否需要制造剑道才能完成这项任务。我想剑道就足够了。上面的代码绑定到我的视图和登录名服务工作没有任何问题。你认为我的问题与JavaScript更相关吗?我看到的三个问题是1)kendo的可观察性和范围;2)IE的行为不同;(你需要澄清dataservice是/做什么)3)身份验证和Web API我试过>>this.Set(“logginging”,true);>>this.Set(“userInfo.logging”,true);>>userInfo.Set(“登录”,true);>>this.parent.Set(“登录”,true);没有运气,总是给出未捕获的typeerror:“set”不是函数,typeerror.“userinfo”没有定义仅供参考:我没有从原始模板更改数据服务。我还将外壳与Visual Studio 2013 SPA模板隔离。我只使用其viewmodel和kendo router登录。数据服务如下所示:varlogin=function(data){return$.ajax(loginUrl,{type:“POST”,data:data});};我尝试过>>userInfo.parent.set(“loggingIn”,false);仍然不走运。非常感谢它现在在Firefox和Chrome中工作。我尝试过var self=this;但实际上我应该使用var that=this;您回答了第二个和第三个问题。我希望我能找到第一个问题的答案:)