https://gist.github.com/1026406
我正在阅读这段代码,我有几个问题。有人可以解释一下这个。
window.LoginView = new LoginView({model: new Credentials()});
任何人都可以解释一下上面的代码是做什么的......请问我的
LoginView
实例的模型为Credentials
。如果是这样,那就有了
我正在使用Credential
。
var Credentials = Backbone.Model.extend({});
如何调用我的REST服务。我不想使用form action
,
我可以从我的JS代码中调用authenticate service
会给我一些flag
。提交我的JS会收集用户名和密码并将其发送到REST Service
。
答案 0 :(得分:0)
LoginView
初始化为一个空的Credentials
模型,当输入发生变化时(nb。this.username.change(..)
和this.password.change(...)
绑定)将会更新。< / p>
Backbone调用REST服务的方法是设置模型的url属性,如url: "path/to/the/rest/service/tied/to/my/model"
,或者将url声明为返回所需路径字符串的函数,如url: function() { ... return pathToMyRestService; }
}。然后可以使用模型的fetch和save方法调用REST服务。
另一种方法是使用jQuery ajax方法,ajax
,post
等。
答案 1 :(得分:0)
查看提供的gist,将在login方法中设置凭据。因此,LoginView提供了一个新的Credentials模型。在Login方法中,用户名和密码被设置为凭据模型。现在,在设置凭据后调用this.model.save()时,模型将被发送到服务器。然后,您可以在服务器上从凭据模型中检索用户名和密码。我认为有更好的方法来验证用户。基本了解REST Authentication。