| 1234567891011121314151617181920212223242526272829303132 |
- function HomeViewModel(app, dataModel) {
- var self = this;
- self.myHometown = ko.observable("");
- Sammy(function () {
- this.get('#home', function () {
- // Make a call to the protected Web API by passing in a Bearer Authorization Header
- $.ajax({
- method: 'get',
- url: app.dataModel.userInfoUrl,
- contentType: "application/json; charset=utf-8",
- headers: {
- 'Authorization': 'Bearer ' + app.dataModel.getAccessToken()
- },
- success: function (data) {
- self.myHometown('你的家乡是:' + data.hometown);
- }
- });
- });
- this.get('/', function () { this.app.runRoute('get', '#home'); });
- });
- return self;
- }
- app.addViewModel({
- name: "Home",
- bindingMemberName: "home",
- factory: HomeViewModel
- });
|