我正在按照教程操作,无法运行以下代码.当我运行以下代码时,我收到错误Can't add property attachToForm, object is not extensible.您是否不再允许以这种方式更改子道具(即使用child.props.key = value)?如果没有,只有当元素是输入时,你能看到更好的方法向嵌套子项添加函数吗?
React.Children.forEach(children, function (child) {
if (child.props.name) {
child.props.attachToForm = this.attachToForm;
child.props.detachFromForm = this.detachFromForm;
}
if (child.props.children) {
this.registerInputs(child.props.children);
}
}.bind(this));
Run Code Online (Sandbox Code Playgroud)
我正在使用es6,如果它改变了什么,但教程可以在这里找到:http://christianalfoni.github.io/javascript/2014/10/22/nailing-that-validation-with-reactjs.html
FormComponent:
'use strict';
import React from 'react';
import BaseComponent from '@client/base-component';
export default class Form extends BaseComponent {
constructor(props) {
super(props);
this.state = {};
}
render() {
var classString = this.props.className ? this.props.className : '';
var classArray = ['_common-form', this.props.type ? 'form--' + this.props.type : …Run Code Online (Sandbox Code Playgroud) 我见过一些非常相似的问题,但我找不到任何问题似乎都有效.我正在尝试npm安装bcrypt但我不断收到下面的错误.
bycrypt是我用来安装bcrypt模块的命令.我确实有Xcode,安装node-gyp似乎没有什么区别
regan@the-Voyagur buddha-bar (feature/styles) $ npm install --save bcrypt
npm WARN package.json mongo@0.1.0 No repository field.
npm WARN package.json mongo@0.1.0 No README data
-
> bcrypt@0.8.0 install /Users/regan/lighthouse/buddha-bar/node_modules/bcrypt
> node-gyp rebuild
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'.
No receipt for 'com.apple.pkg.DeveloperToolsCLILeo' found at '/'. …Run Code Online (Sandbox Code Playgroud) 我对如何做到这一点感到有点失落.
我有一个网页.我希望用户向下滚动,然后在距离顶部特定距离处我希望鼠标滚动以实现元素位置(使其看起来像是元素滚动).然后,当该元素到达某个位置时(即顶部:-500),我希望滚动再次应用于主网页.有关如何做到这一点的任何想法?
我现在正在努力工作,但没有任何运气,我会在有东西展示时发布
编辑:解决方案/ sudo代码的开头https://jsfiddle.net/vk0jk37v/23/
附件是我正在申请这个的一个区域的图像.
//pageFeature.style.backgroundPosition = "0px " + parseInt(-y / 6) + 'px');
var element = document.getElementById('container').getBoundingClientRect();
var elementTop = element.top //distance from top 720;
// variable to stop function from being replayed on scroll when scrolling image
var isScrollingImage = false;
// disables scroll on body
var disableScroll = function() {
document.body.style.overflow='hidden';
}
// enables scroll on body
var enableScroll = function() {
document.body.style.overflow='auto';
}
//change position of background along y axis with scroll
var …Run Code Online (Sandbox Code Playgroud) 我一直试图让它工作一段时间而不确定如何做以下事情.我的表单组件包含包含常规html标记和输入的子项.如果孩子是输入我想添加attachToForm和detachFromForm功能.如果它不是输入,我想继续遍历子项以确保该元素没有子输入字段.无论元素是否输入,我仍然希望它出现在我的页面上,我只想将这些函数添加到输入中.
问题是我只能让我的函数只返回输入,删除标签和标题.我知道这是因为我只添加了带有输入的元素到newChildren,但是如果我推动其他元素在else if部分我得到重复,我可以想到另一种方式来做到这一点.我不确定我是不是不了解基本的JS或者有大脑缺口.
React.Children.forEach(children, function(child) {
var current = child;
if (child.props && child.props.name) {
this.newChildren.push(React.cloneElement(child, {
detachFromForm: this.detachFromForm,
attachToForm: this.attachToForm,
key: child.props.name
}));
} else if (child.props && child.props.children){
this.newChildren.push(child);
this.registerInputs(child.props.children);
} else {
*need to keep track of parent elements and elements that do not have inputs
}
}.bind(this));
Run Code Online (Sandbox Code Playgroud)
编辑:不确定是否需要,但这是和遍历的示例形式
return (
<Modal className="_common-edit-team-settings" title={`Edit ${this.props.team.name}`} isOpen={this.props.modalIsOpen && this.props.editTeamModal} onCancel={this.props.toggleEditTeamModal} backdropClosesModal>
<Form onSubmit={this.saveChanges}>
<FormSection className="edit-team-details" sectionHeader="Team Details">
<FormField label="Name">
<Input name="name" value={this.state.values.name} onChange={this.handleInputChange} type="text" …Run Code Online (Sandbox Code Playgroud) 我有一个控制输入,最初显示的值.我已将该输入设置为autoFocus,但是当我希望它在最后出现时,光标出现在输入的开头.我理解这可能是因为autoFocus是在值之前添加的,但我不是100%肯定.
在输入字段结束时完成光标初始化的最佳方法是什么?
var Test = React.createClass({
getInitialState: function() {
return {
teamId: 'fdsfds'
};
},
render: function() {
return (
<input type="text" autoFocus value={this.state.teamId} onChange={this.setTeamId} />
);
},
setTeamId: function(event) {
this.setState({ teamId: id });
},
});
ReactDOM.render(
<Test />,
document.getElementById('container')
);
Run Code Online (Sandbox Code Playgroud)
您好我正在使用Jasmine编写我的第一个角度测试,但我一直收到错误
------测试开始:文件:C:\ Users\Regan\Documents\Visual Studio 2013\WebSites\Regan\testApp\TestProject \ng-tests\MainCtrlSpec.js ------使用内联测试'MainCtrl mock:应该有标签'失败错误:[$ injector:unpr]未知提供者:$ scopeProvider < - $ scope < - MainCtrl
我试过玩它但是卡住了.如果您发现问题,请告诉我.如果您还需要更多代码,请告诉我,但我认为问题出在这两个文件中.
MainCtrlSvc.js
/// <reference path="../../Scripts/angular/angular.js" />
/// <reference path="../../Scripts/angular/angular-mocks.js" />
/// <reference path="../../Scripts/chartjs/Chart.js" />
/// <reference path="../../Scripts/angular-chart.js-master/dist/angular-chart.js" />
/// <reference path="../../Scripts/controller/main-controller.js" />
/// <reference path="../../Scripts/service/data-service.js" />
/// <reference path="../../libs/jasmine/jasmine.js" />
describe("MainCtrl with inline mock", function () {
beforeEach(module("ChartApp"));
var ctrl, mockDataSrv;
beforeEach(module(function($provide) {
mockDataSrv = {
labels: ["Reading", "Coding", "Thinking About Coding", "Reddit", "StackOverflow"],
data: [500, 300, 300, 40, 220],
type: "PolarArea",
title: …Run Code Online (Sandbox Code Playgroud) 我正在尝试测试一个指令(你可以看到完整的细节: 单元测试角度指令 - 非常卡住)
我坚持的一件事就是找出具体的scope.$new(true)方法.从我可以发现它看起来像$ new创建一个新的子范围,但是什么是(真)部分并且做角度自动执行,因为它不在我的代码中但它仍然被抛出作为错误TypeError: 'undefined' is not a function (evaluating 'scope.$new(true)')
javascript ×4
reactjs ×3
angularjs ×2
css ×1
html ×1
mean ×1
node.js ×1
npm ×1
unit-testing ×1