草庐IT

mobx-state-tree

全部标签

javascript - 如何知道鼠标按钮的当前状态(mouseup state or mousedown state)

在Javascript中,当我单击滚动条(页面中出现的任何滚动条)并将鼠标悬停在图像上时,图像再次开始拖动。图像只能在鼠标按钮按下状态下拖动。所以我试图通过了解鼠标按钮状态(mousedown或mouseup)来解决这个问题这个问题只存在于IE和chrome,我试过的其他浏览器都不存在。Javascript:document.onmousemove=mouseMove;document.onmousedown=mouseDown;document.onmouseup=mouseUp;functionmouseMove(ev){varmouseButtonState;//putcodeh

javascript - 防止 this.state 与 setState 一起使用

Thereference状态:setState()doesnotalwaysimmediatelyupdatethecomponent.Itmaybatchordefertheupdateuntillater.Thismakesreadingthis.staterightaftercallingsetState()apotentialpitfall.Instead,usecomponentDidUpdateorasetStatecallback(setState(updater,callback)),eitherofwhichareguaranteedtofireaftertheupd

javascript - react : Get initialstate after state has changed

是否有可能在状态改变后检索初始状态?例如:React.createClass({getInitialState:function(){return{foo:'bar'}},componentWillMount:function(){this.setState({foo:'foo'})},componentDidMount:function(){//gettheinitialstate"bar"?}})我在文档中找不到任何内容。我当然可以将值保存在外部变量中,但我只是好奇是否可以将初始状态视为可以重复使用的“配置”对象。 最佳答案 不

javascript - 无法根据文档在 Angular ui-router 中访问 $state.current.data

我正在尝试动态更新页面标题。考虑这样定义的状态:$stateProvider.state('login',{url:'/login',templateUrl:'/templates/views/login.html',controller:'AuthCtrl',data:{title:'Login'}}在页面的HEAD部分:根据tothedocumentation,Iamsupposedtobeabletoaccessmycustomdataproperty:app.directive("pageTitle",function($state){return{restrict:'A',t

javascript - 当 var trees = new Array ("redwood", "bay", "cedar"时 0 如何成为树的属性)

这个问题在这里已经有了答案:Accessnumericpropertiesofanobjectusingdotnotation(2个答案)关闭11个月前。我在mozilla文档中看到了这个例子,但我不明白为什么。如果0是树的属性,我原以为trees.0会返回redwood但这是一个错误的陈述。a[0]是一种访问数组0属性的方法吗?在这种情况下,a["length"]也应该有效(逻辑上)。谁能说清楚?链接:developer.mozilla.orgvartrees=newArray("redwood","bay","cedar","oak","maple");0intrees;//ret

javascript - 不要直接改变状态。使用 setState() react/no-direct-mutation-state

我有这个代码:constructor(props){super(props)this.state={loginButton:'',benchmarkList:''}if(props.username==null){this.state.loginButton=}else{}}它给我一个ESLint警告:Donotmutatestatedirectly.UsesetState()react/no-direct-mutation-state.现在我该怎么办,因为我不能在constructor中直接使用setState,因为它会创建error像这样更新会给我错误。

javascript - 在 React/React Native 中使用构造函数与 state = {} 有什么区别?

这个问题在这里已经有了答案:Whatisthedifferencebetweenusingconstructorvsstate={}todeclarestateinreactcomponent?(3个答案)关闭4年前。我都看过exportdefaultclassLoginScreenextendsReact.Component{constructor(props){super(props);this.state={loading:false,loggedIn:false,}}}和exportdefaultclassLoginScreenextendsReact.Component{st

javascript - 在javascript中将文件/目录结构转换为 'tree'

我有一个看起来像这样的对象数组:[{name:'test',size:0,type:'directory',path:'/storage/test'},{name:'asdf',size:170,type:'directory',path:'/storage/test/asdf'},{name:'2.txt',size:0,type:'file',path:'/storage/test/asdf/2.txt'}]可以有任意数量的任意路径,这是遍历目录中的文件和文件夹的结果。我要做的是确定这些的“根”Node。最终,这将存储在mongodb中并使用物化路径来确定它的关系。在此示例中,/s

javascript - 未捕获的类型错误 : Cannot read property 'toUpperCase' of undefined react state item

我是React和Javascript的新手,我正在尝试呈现以下React组件:'usestrict';varReact=require('react');importToReadListfrom'./toreadlist.js';varToRead=React.createClass({getInitialState:function(){return{bookTitles:[]};},handleSubmit:function(e){e.preventDefault();this.state.bookTitles.push(React.findDOMNode(this.refs.bo

javascript - 将 $stateParams 和 $state 注入(inject) Jasmine Angular js 测试变得未定义

我正在为我的DetailCtrl编写jasmine测试。我有10个json文件,每个文件的文件名都是这样1.json2.json3.json在我的数据文件夹中这是我的详细控制backpagecontrollers.controller('DetailCtrl',function($scope,$stateParams,$http){$http.get('data/'+$stateParams.listingId+'.json').success(function(data){$scope.extrainfo=data;});});细节Controller正在从我的数据文件夹中获取每个1