gpt4 book ai didi

typescript - hottowel (durandal) + typescript

转载 作者:搜寻专家 更新时间:2023-10-30 20:39:05 24 4
gpt4 key购买 nike

这是我的第一篇文章,祝我好运:)

我想使用 hot towel(durandal) + typescript ,我遵循了这些线程:- how-can-i-use-a-class-for-my-shell-viewmodel-in-durandal- how-to-use-fancybox-in-combination-with-durandal-en-typescript- incorrect-this-in-select

也试过DurandalTypescriptExample样本

此示例未运行并出现此错误:

“‘/’应用程序中的服务器错误。

找不到资源。 "

起初我决定只用 typescript 改变我的 View 模型,然后在那个 shell 之后,但在这两种情况下我都得到了这个错误:

这是我的 shell.ts 代码(我使用了 this 示例):

/// <reference path="../durandal/durandal.d.ts" />

import _router = module('durandal/plugins/router');
import app = module('durandal/app');

export var router = _router;

export function search() {
app.showMessage('Search not yet implemented...');
}
export function activate() {
return router.activate('welcome');
}

我得到了这个错误:

- JavaScript runtime error: 'exports' is undefined

有什么想法吗?

如果可能的话,我们会感谢可行的解决方案。

谢谢大家,让我们看看会发生什么。

最佳答案

我在使用 DurandalTypescriptExample 时遇到了同样的问题。然而,该项目中的代码演示了如何在 viewmodel 文件中实现 typescript 代码,前提是您只确保公开处理 durandal 所需的变量。至少 activate 函数和 title 变量。

参见下面的代码示例:

/// <reference path="../../dts/knockout/knockout.d.ts" //>
export class ViewModel {
title: string = 'Home View';
MyTitle: KnockoutObservableString; //MyTitle can be referenced in home.html as vm.MyTitle
public activate() {
this.MyTitle = ko.observable(this.title + " with my ko title");
return true;
}
}

export var vm = new ViewModel();
//The Durandal plugin-interface variables
export var title = vm.title;
export var activate = function () { return vm.activate(); };

由于我找不到现成的项目来演示这一点,所以我不得不自己制作。在 github 上查看我的 Hot Towel 项目版本:

https://github.com/Svakinn/TypeTowel

关于typescript - hottowel (durandal) + typescript ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16633877/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com