我将我的数据存储在我的react组件正在使用的角度控制器中,问题是当我更改我的数据时,我的react组件不会重新呈现。我正在尝试使用componentWillReceiveProps,但是这个组件不是以常规的方式使用<react-component>调用的,所以我认为它不会工作。我尝试了helped.Can -depth= "reference/value“,但是仍然没有人告诉我应该如何强制我的组件重新呈现?
控制器:
app.controller('MainCtrl', function ($scope) {
$scope.myComponent = {};
console.log($scope.myComponent);
console.log(document.body.children[0].children[0]);
$scope.resultProps = {
item:[]
}
$scope.firstArrayProps = {
item:[],
result:$scope.resultProps
}
$scope.secondArrayProps = {
item:[],
result:$scope.resultProps
}
$(document.body.children[0].children[0]).keydown(function(e) {
console.log('voala');
var key = e.which || e.keyCode;
if(key == 46) {
console.log('voala');
setTimeout(function () {
$scope.firstArrayProps.item.length = 0; //HERE IM CHANGING DATA
}, 1000);
}
});
...react组件:
var DiaryTable = React.createClass({displayName: "DiaryTable",
getInitialState: function() {
return {
items : this.props.item,
globalChecked:false
};
},
....html:
<body ng-app="app" ng-controller="MainCtrl as mainCtrl">
<div class="tableWrapper">
<react-component name="DiaryTable" props="firstArrayProps" watch-depth="value"/>
</div>
<button class="myMergeButton" id="mergeButton" ng-click="runMerge()">Merge diaries</button>
<div class="tableWrapper">
<react-component name="DiaryTable" props="secondArrayProps" watch-depth="value"/>
</div>
...发布于 2016-08-24 03:37:19
应该使用AngularJS ng-keydown指令添加键控处理程序。
<div class="tableWrapper" ng-keydown="voala($event)">
<react-component name="DiaryTable"
props="firstArrayProps"
watch-depth="value">
</react-component>
</div>然后将函数添加到控制器中:
app.controller('MainCtrl', function ($scope, $timeout) {
$scope.voala = function(e) {
console.log('voala');
var key = e.which || e.keyCode;
if(key == 46) {
console.log('voala');
$timeout(function () {
//HERE IM CHANGING DATA
$scope.firstArrayProps.item.length = 0;
}, 1000);
}
});
});ng-keydown指令和$timeout服务都与AngularJS摘要周期正确集成。
https://stackoverflow.com/questions/39089685
复制相似问题