小编San*_*rog的帖子

如何将js-modules导入TypeScript文件?

我有一个包含这样一个文件的Protractor项目:

var FriendCard = function (card) {
    var webElement = card;
    var menuButton;
    var serialNumber;

    this.getAsWebElement = function () {
        return webElement;
    };

    this.clickMenuButton = function () {
        menuButton.click();
    };

    this.setSerialNumber = function (numberOfElements) {
        serialNumber = numberOfElements + 1;
        menuButton = element(by.xpath('.//*[@id=\'mCSB_2_container\']/li[' + serialNumber + ']/ng-include/div/div[2]/i'));
    };

    this.deleteFriend = function () {
        element(by.css('[ng-click="deleteFriend(person);"]')).click();
        element(by.css('[ng-click="confirm()"]')).click();
    }
};
module.exports = FriendCard;
Run Code Online (Sandbox Code Playgroud)

该文件的路径是

./pages/FriendCard.js

我没有问题,使用require()方法导入到另一个文件:

var FriendCard = require('./../pages/FriendCard');
Run Code Online (Sandbox Code Playgroud)

所以,我决定将这个文件导入到TypeScript文件中:

import {FriendCard} from './../pages/FriendCard'
Run Code Online (Sandbox Code Playgroud)

我正在使用WebStorm,所以它告诉我,(TS2305)它没有导出成员'FriendCard'.

也许我必须以某种方式配置tsconfig.json文件,但我仍然不知道它是如何工作的.你可以帮帮我吗?

javascript webstorm typescript protractor

52
推荐指数
5
解决办法
10万
查看次数

Golang中将整数数组中的数字连接成一个数字?

我有一个整数数组:

nums := []int{1, 2, 3}
Run Code Online (Sandbox Code Playgroud)

我怎样才能从中得到整数 123 呢?

go

5
推荐指数
1
解决办法
6993
查看次数

可以混合使用C和Swift吗?

我已经研究了Swift和一些C的基础知识.我怎样才能在一个项目中结合C和Swift?我可以忽略Objective-C吗?

c swift

4
推荐指数
1
解决办法
1418
查看次数

如何在Android上"单元测试"json解析(JSONObject =="null")?

我有一些问题.我已经创建了JSONParser,需要对它进行单元测试.但是,如果我尝试使用有效JSON的副本传递String对象,则每次JSONObject(我的Parser的一部分)都具有null值.

这里的例子.

我正在分配给字符串的JSON:

public class JSONParserTest {
    private JSONParser parser;
    private Translations translations;
    private String nounsAndAdjectivesJson = "{\"head\":{},\"def\":[{\"text\":\"house\",\"pos\":\"noun\",\"ts\":\"ha?s\",\"tr\":[{\"text\":\"???\",\"pos\":\"???????????????\",\"gen\":\"?\",\"syn\":[{\"text\":\"?????\",\"pos\":\"???????????????\",\"gen\":\"?\"},{\"text\":\"????\",\"pos\":\"???????????????\",\"gen\":\"?\"}],\"mean\":[{\"text\":\"home\"},{\"text\":\"cottage\"}],\"ex\":[{\"text\":\"white house\",\"tr\":[{\"text\":\"????? ???\"}]},{\"text\":\"wooden house\",\"tr\":[{\"text\":\"?????????? ?????\"}]}]},{\"text\":\"?????????\",\"pos\":\"???????????????\",\"gen\":\"??\",\"syn\":[{\"text\":\"??????\",\"pos\":\"???????????????\",\"gen\":\"??\"}],\"mean\":[{\"text\":\"room\"},{\"text\":\"building\"}],\"ex\":[{\"text\":\"house of parliament\",\"tr\":[{\"text\":\"?????? ??????????\"}]}]},{\"text\":\"?????????\",\"pos\":\"???????????????\",\"gen\":\"?\",\"mean\":[{\"text\":\"hotel\"}]},{\"text\":\"?????\",\"pos\":\"???????????????\",\"gen\":\"?\",\"mean\":[{\"text\":\"family\"}]},{\"text\":\"?????????\",\"pos\":\"???????????????\",\"gen\":\"??\",\"mean\":[{\"text\":\"farm\"}]},{\"text\":\"?????\",\"pos\":\"???????????????\",\"gen\":\"?\",\"mean\":[{\"text\":\"theatre\"}]},{\"text\":\"??????\",\"pos\":\"???????????????\",\"gen\":\"?\",\"mean\":[{\"text\":\"chamber\"}],\"ex\":[{\"text\":\"house of representatives\",\"tr\":[{\"text\":\"?????? ??????????????\"}]}]},{\"text\":\"?????\",\"pos\":\"???????????????\",\"gen\":\"??\",\"syn\":[{\"text\":\"??????\",\"pos\":\"???????????????\",\"gen\":\"??\"}],\"mean\":[{\"text\":\"housing\"}],\"ex\":[{\"text\":\"safe houses\",\"tr\":[{\"text\":\"?????????? ?????\"}]},{\"text\":\"traditional house\",\"tr\":[{\"text\":\"???????????? ??????\"}]}]},{\"text\":\"???\",\"pos\":\"???????????????\",\"gen\":\"?\",\"mean\":[{\"text\":\"kind\"}]},{\"text\":\"?????\",\"pos\":\"???????????????\",\"gen\":\"?\",\"mean\":[{\"text\":\"cutting\"}]},{\"text\":\"????????\",\"pos\":\"???????????????\",\"gen\":\"?\",\"mean\":[{\"text\":\"dynasty\"}]},{\"text\":\"???????\",\"pos\":\"???????????????\",\"gen\":\"?\",\"mean\":[{\"text\":\"audience\"}]},{\"text\":\"?????\",\"pos\":\"???????????????\",\"gen\":\"?\",\"mean\":[{\"text\":\"market\"}]}]},{\"text\":\"house\",\"pos\":\"adjective\",\"ts\":\"ha?s\",\"tr\":[{\"text\":\"????????\",\"pos\":\"??????????????\",\"mean\":[{\"text\":\"home\"}],\"ex\":[{\"text\":\"house arrest\",\"tr\":[{\"text\":\"???????? ?????\"}]}]},{\"text\":\"???????\",\"pos\":\"??????????????\",\"ex\":[{\"text\":\"house mouse\",\"tr\":[{\"text\":\"??????? ????\"}]}]},{\"text\":\"?????????\",\"pos\":\"??????????????\",\"mean\":[{\"text\":\"room\"}]}]},{\"text\":\"house\",\"pos\":\"verb\",\"ts\":\"ha?s\",\"tr\":[{\"text\":\"?????????????????\",\"pos\":\"??????\",\"asp\":\"?????\"},{\"text\":\"???????????\",\"pos\":\"??????\",\"asp\":\"?????\",\"mean\":[{\"text\":\"host\"}]},{\"text\":\"????\",\"pos\":\"??????\",\"asp\":\"?????\",\"mean\":[{\"text\":\"live\"}]},{\"text\":\"???????\",\"pos\":\"??????\",\"asp\":\"?????\",\"mean\":[{\"text\":\"accommodate\"}]},{\"text\":\"????????\",\"pos\":\"??????\",\"asp\":\"???\",\"syn\":[{\"text\":\"????????\",\"pos\":\"??????\",\"asp\":\"???\"}],\"mean\":[{\"text\":\"settle\"},{\"text\":\"shelter\"}]},{\"text\":\"????????\",\"pos\":\"??????\",\"asp\":\"?????\",\"mean\":[{\"text\":\"place\"}]}]}]}";
    private String verbsJson = "{\"head\":{},\"def\":[{\"text\":\"peek\",\"pos\":\"verb\",\"ts\":\"pi?k\",\"tr\":[{\"text\":\"?????????\",\"pos\":\"??????\",\"asp\":\"???\",\"syn\":[{\"text\":\"?????????\",\"pos\":\"??????\",\"asp\":\"???\"},{\"text\":\"???????????\",\"pos\":\"??????\",\"asp\":\"?????\"}],\"mean\":[{\"text\":\"glance\"},{\"text\":\"look\"}],\"ex\":[{\"text\":\"peek inside\",\"tr\":[{\"text\":\"????????? ??????\"}]}]},{\"text\":\"?????????\",\"pos\":\"??????\",\"asp\":\"???\",\"syn\":[{\"text\":\"???????????\",\"pos\":\"??????\",\"asp\":\"?????\"},{\"text\":\"????????????\",\"pos\":\"??????\",\"asp\":\"?????\"}],\"mean\":[{\"text\":\"look\"},{\"text\":\"peep\"}]}]},{\"text\":\"peek\",\"pos\":\"noun\",\"ts\":\"pi?k\",\"tr\":[{\"text\":\"??????? ??????\",\"pos\":\"???????????????\",\"mean\":[{\"text\":\"quick look\"}]},{\"text\":\"?????? ????????\",\"pos\":\"???????????????\"},{\"text\":\"???\",\"pos\":\"???????????????\",\"gen\":\"?\",\"mean\":[{\"text\":\"peak\"}]}]}]}";

    @Before
    public void setUp() throws Exception {
        translations = new Translations();
    }

    @Test
    public void testVerbsOnlyParsing() throws JSONException{
        JSONObject jsonObject = new JSONObject(verbsJson);
        parser = new JSONParser(jsonObject);
        translations = parser.getTranslations();
        Assert.assertNotNull(translations.getVerbs());
    }
}
Run Code Online (Sandbox Code Playgroud)

我对JSONParser的单元测试 …

android json unit-testing

3
推荐指数
1
解决办法
1618
查看次数

在 TreeSet 中 NavigableMap 的 put() 方法的实现在哪里?

我只是想调试 TreeSet 的方法 add() 是如何工作的,特别是如何在 TreeSet 内部组织排序过程。

所以当我们查看 TreeSet 类的内部时,我们会看到方法 add(E e)

    public boolean add(E e) {
        return m.put(e, PRESENT)==null;
    }
Run Code Online (Sandbox Code Playgroud)

好的,什么是m变量?

    private transient NavigableMap<E,Object> m;
Run Code Online (Sandbox Code Playgroud)

好吧,我们从Map接口中搜索put()方法的实现......嗯...... 最好的东西,能找到的是TreeMap中的实现......但是TreeSet的具体实现在哪里?

java

1
推荐指数
1
解决办法
31
查看次数

如何在同一域上运行Golan应用程序(后端)和ReactJS应用程序(前端)以防止CORS?

所以,我有一个golang应用程序和reactJs应用程序。如果我在不同的域上运行它们,则会遇到CORS问题。

在服务器端允许CORS根本不是问题,但是我无法从服务器获取cookie,因为浏览器会将它们作为第三方cookie忽略。

因此,我看到了一个非常简单的解决方案-在同一域上运行服务器和前端,但是我不知道该怎么做。如何配置所有内容以使其在同一域上运行而不会发生冲突?防止golang应用程序和ReactJS应用程序之间发生CORS的最佳实践是什么?

go reactjs

0
推荐指数
1
解决办法
1180
查看次数

标签 统计

go ×2

android ×1

c ×1

java ×1

javascript ×1

json ×1

protractor ×1

reactjs ×1

swift ×1

typescript ×1

unit-testing ×1

webstorm ×1