小编Tyl*_*ang的帖子

如何在textinput中集中文本

一个简短的问题.
有没有办法在react-native中集中文本Textinput

这是jsx中的标记:

<TextInput style={styles.input} placeholder="Your Account" />
Run Code Online (Sandbox Code Playgroud)

在styles.input中,只是尝试添加textAlign:"center",它不起作用.

和将alignAlign添加到标记作为属性一样.有人帮我一个忙吗?谢谢.

javascript react-native

24
推荐指数
2
解决办法
3万
查看次数

如何捕获角度ng-include错误

当我ng-include用作标题时,如何在地址(文件路径)不存在时捕获错误?

我完成了一个ng-include router内部ng-view(with ng-route),它有点像这样:

ContentCtrl:

var content = $route.current.params.content,
    tmplArr = content.split("_"),
    tmpl = {},
    personId=$route.current.params.personId||$scope.persons[0].id;
$scope.personId=personId;
tmpl.url = "content/";
for (var i = 0, len = tmplArr.length; i < len; i++) {
    tmpl.url += tmplArr[i] + "/";
}
tmpl.url = tmpl.url.substring(0, tmpl.url.length - 1) + ".html";
$scope.template = tmpl;
Run Code Online (Sandbox Code Playgroud)

ContentView:

<div ng-include="template.url" class="ng-animate"></div>
Run Code Online (Sandbox Code Playgroud)

当我使用addr时不存在如:/ home /#/ content/profile_asdfa,angular只是在循环中获取资源.所以当哈希中没有模板文件时,我需要捕获ng-include错误.有谁能够帮我 ?谢谢!

javascript angularjs angularjs-ng-include

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

安装nodeBB时出现node-gyp rebuild status 1问题

我试图安装nodeBB,这是一个开源论坛系统.

当我尝试在此github页面中运行该命令时.我收到以下错误消息,

> mmmagic@0.3.15 install /Users/tyler/Work/forum/NodeBB/node_modules/mmmagic
> node-gyp rebuild

gyp WARN install got an error, rolling back install
gyp ERR! configure error 
gyp ERR! stack Error: EPERM, utime '/Users/tyler/.node-gyp/0.12.7'
gyp ERR! stack     at Error (native)
gyp ERR! System Darwin 14.4.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/tyler/Work/forum/NodeBB/node_modules/mmmagic
gyp ERR! node -v v0.12.7
gyp ERR! node-gyp -v v2.0.1
gyp ERR! not ok 
npm ERR! Darwin 14.4.0
npm ERR! argv "node" "/usr/local/bin/npm" "install"
npm ERR! node v0.12.7 …
Run Code Online (Sandbox Code Playgroud)

xcode node.js node-gyp

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

JavaScript中的代码"length === + length"是什么意思?

我只是阅读了底层源代码,并且无法从这段代码中获得观点:

_.each = _.forEach = function(obj, iterator, context) {
    if (obj == null) return obj;
    iterator = createCallback(iterator, context);
    var i, length = obj.length;
    if (length === +length) {   // why +length?
        for (i = 0; i < length; i++) {
            iterator(obj[i], i, obj);
        }
    } else {
        var keys = _.keys(obj);
        for (i = 0, length = keys.length; i < length; i++) {
            iterator(obj[keys[i]], keys[i], obj);
        }
    }
    return obj;
};
Run Code Online (Sandbox Code Playgroud)

为什么长度=== +长度?如果长度不是数字,我想这用于强制转换?有人可以帮我一把吗?

javascript

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

React 中测试元素顺序的方法

Jest只是想使用和为我的反应组件实现单元测试 Enzyme

有没有办法测试订单?假设我有组件Button,我想同时渲染图标和文本。

当然,向用户提供对齐选项(图标优先或子元素优先)是件好事。

按钮.js

class Button extends React.Component {
    constructor() {
        super();
    }
    render() {
        let content;
        const icon = (<Icon type='search' />);
        if (this.props.iconAlign === 'right') {
            content = (<span>{this.props.children} {icon}</span>
        } else {
            content = (<span>{icon} {this.props.children}</span>
        }
        return (
            <button>{content}</button>
        );
    }
}
Run Code Online (Sandbox Code Playgroud)

如何用JestEnzymeiconAlign测试道具?

reactjs jestjs enzyme

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

在TJ的告别帖中Node.js错误处理中"没有得到回调"是什么意思?

最近,我读过TJ的博客文章:"Farewell Node.js".

我不太了解Node失败的部分.这里是:

在我看来,Go中的错误处理是优越的.节点很棒,因为你必须考虑每个错误,并决定做什么.然而节点失败是因为:

  • 你可能会得到重复的回调
  • 你可能根本没有得到回调(迷失方向)
  • 你可能会得到带外错误
  • 发射器可能会发生多个"错误"事件
  • 缺少"错误"事件将一切都发送到地狱
  • 经常不确定什么需要"错误"处理程序
  • "错误"处理程序非常冗长
  • 回调很糟糕

当作者写道"你可能根本没有得到回调(陷入困境)"时,会提到什么具体问题?

javascript node.js

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

尾调用优化在 babel ES2015 中不起作用

刚刚在 Node.js 中实现了尾调用示例代码,将使用 babel(启用 ES2015 语法支持)进行翻译,但它只是抛出异常Maximum call stack size exceeded

//index.js
require('babel-core/register');
require('./sample.js');

//sample.js
function factorial(n, acc = 1) {
    'use strict';
    if (n <= 1) return acc;
    return factorial(n - 1, n * acc);
}

// Stack overflow in most implementations today,
// // but safe on arbitrary inputs in ES6
factorial(100000)
Run Code Online (Sandbox Code Playgroud)

这是我的 babel 依赖。

??? babel-core@6.2.1
? ??? babel-code-frame@6.1.18
? ? ??? chalk@1.1.1
? ? ? ??? ansi-styles@2.1.0
? ? ? ??? escape-string-regexp@1.0.3
? ? ? …
Run Code Online (Sandbox Code Playgroud)

javascript ecmascript-6 babeljs

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