【发布时间】:2013-08-25 08:08:26
【问题描述】:
目前我正在处理Durandal 2.0 项目。 最初我使用这个 JavaScript 代码来执行我的 shell.js(ViewModel),它工作得非常好。
初始 JavaScript 代码(工作中的一个)
define(['plugins/router', 'durandal/app'], function (router, app) {
return {
router: router,
search: function() {
app.showMessage('Search not yet implemented...');
},
activate: function () {
router.map([
{ route: '', title:'Welcome', moduleId: 'viewmodels/welcome', nav: true },
{ route: 'flickr', moduleId: 'viewmodels/hello', nav: true }
]).buildNavigationModel();
return router.activate();
}
};
});
现在我正在尝试使用打字稿。 所以我写了这段代码(下一个),它不起作用 打字稿代码:
/// <reference path="../../Scripts/typescripts/jquery/jquery.d.ts" />
/// <reference path="../../Scripts/typescripts/knockout/knockout.d.ts" />
/// <reference path="../../Scripts/typescripts/durandal/durandal.d.ts" />
import _config = require('config');
import _router = require('plugins/router');
import _app = require('durandal/app');
class shell {
//config = new _config.Config();
app = _app;
router = _router;
activate() {
this.router.map([
{ route: '', title: 'Welcome', moduleId: 'viewmodels/welcome', nav: true },
{ route: 'flickr', moduleId: 'viewmodels/hello', nav: true }
]).buildNavigationModel();
return this.router.activate();
}
}
打字稿的输出: TypeScript 生成的 JavaScript 代码(不工作)
/// <reference path="../../Scripts/typescripts/jquery/jquery.d.ts" />
/// <reference path="../../Scripts/typescripts/knockout/knockout.d.ts" />
/// <reference path="../../Scripts/typescripts/durandal/durandal.d.ts" />
define(["require", "exports", 'plugins/router', 'durandal/app'], function(require, exports, ___router__, ___app__) {
var _router = ___router__;
var _app = ___app__;
var shell = (function () {
function shell() {
//config = new _config.Config();
this.app = _app;
this.router = _router;
}
shell.prototype.activate = function () {
this.router.map([
{ route: '', title: 'Welcome', moduleId: 'viewmodels/welcome', nav: true },
{ route: 'flickr', moduleId: 'viewmodels/hello', nav: true }
]).buildNavigationModel();
return this.router.activate();
};
return shell;
})();
});
谁能建议我这是什么问题? 我得到的错误是这样的,
无法解析绑定。
绑定值:attr: { href: router.navigationModel()[0].hash }
消息:路由器未定义;
视图:视图/shell;
ModuleId:viewmodels/shell
【问题讨论】:
-
你在编译过程中遇到了什么错误,你使用的是什么版本的 Typescript?
-
您不是从模块返回外壳,而是从构造函数返回。
标签: javascript knockout.js viewmodel typescript durandal