Angular.js模型第一次没有更新

[英]Angular.js model not updateing after first time


I have an example here: http://www.search-this.com/examples/angular-help/

我在这里有一个例子:http://www.search-this.com/examples/angular-help/

If you double-click "Text Message" in the list it brings up an input box. type "one" in the input box and click the update button. Notice the console.log click SmsResponseActionParmAndValue to expand and locate the "Text Message" option click ParmAndValue to expand and notice the Value property has our "one" value we typed in.

如果双击列表中的“文本消息”,则会弹出一个输入框。在输入框中键入“one”,然后单击“更新”按钮。注意console.log单击SmsResponseActionParmAndValue以展开并找到“Text Message”选项单击ParmAndValue以展开并注意Value属性具有我们输入的“one”值。

Now type two in the input box and look at the console.log and notice it doesn't update? It only updates the first time?

现在在输入框中键入两个并查看console.log并注意它不会更新?它只是第一次更新?

Help please...

2 个解决方案

#1


0  

which is getting updated in selected object not in main JSON object.

在所选对象中更新,而不是在主JSON对象中。

$scope.updateDetails = function () {

$ scope.updateDetails = function(){

    console.log("update");
    console.log($scope.actions); //
    console.log($scope.selectedAction); // look in this object updated you have to override it to original object or use 2 times ng-repeat to bind.
};

#2


0  

This is very ugly i know but its a solution:

这是非常难看我知道,但它的解决方案:

   $scope.updateDetails = function() {

      angular.forEach($scope.actions.SmsResponseActionParmAndValue,function(action){
          if(action.Description === $scope.selectedAction.Description){
               console.log($scope.selectedAction)
               action.ParmAndValue = $scope.selectedAction.ParmAndValue
               return;
          }
      });

      console.log($scope.actions)
   };

The problem is that the updated model doesn't point to the same array in memory as the original object so we have to update the array that the original object points to.

问题是更新的模型没有指向内存中与原始对象相同的数组,因此我们必须更新原始对象指向的数组。

智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2016/02/11/4ca7923c6d5cdbb2d1f661107e2de755.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告