2015-02-12 43 views
0

中的更改im试图查看发送到函数cronSave(user_id,script_id,cron_format)的值。问题是cron_format<contenteditable>属性和功能将仅显示值innitialized表没有得到的变化.. 这是表:ng-click不会识别表

<p id="demo">Display data here</p> 

<main> 
    <table class="table table-bordered table-hover" ng-controller="tableCtrl"> 
     <thead> 
     <th>user name</th> 
     <th>script name</th> 
     <th>cron format<span class="glyphicon glyphicon-question-sign"></span></th> 
     </thead> 
     <tbody> 
      <tr ng-repeat="row in data"> 
       <td class="userName">{{row.user_id}}</td> 
       <td class="scriptName">{{row.script_id}}</td> 
       <td class="cronFormat"><span contenteditable="true" ng-repeat="l in letters(row.cron_format) track by $index">{{l}}</span><button class="save" ng-click="saveCron(user_id,script_id,cron_format)">save</button></td> 
     </tbody> 
    </table> 
</main> 

,这是JS:

var app = angular.module('app', []); 

//Table Controller 
app.controller('tableCtrl',function($scope) { 
$scope.data = [ 
     {user_id: "1", script_id: "s12", cron_format: "*/2 * * 5 *"}, 
     {user_id: "2", script_id: "s34", cron_format: "*/5 * * * *"}, 
     {user_id: "3", script_id: "s54", cron_format: "*/4 * 7 * *"}, 
    {user_id: "4", script_id: "s234", cron_format: "*/6 * * * *" } 
    ]; 
    //parse cron_format and edit each digit individually 
    $scope.letters = function(row.cron_format){ 
     return cron_format.split(" "); 
    } 
    //save cron changes if exits/create if doesn't 

    $scope.saveCron = function(userId,scriptId,cronFormat){ 
     $.post("updateCronChange.php","user_id=userId&script_id=scriptId&cron=cronFormat", function(data){ 
      document.getElementById("demo").innerHTML = userId + scriptId + cronFormat; // Get the element with id="demo" 
     }); 
    } 
}); 

所以如果在一个行用户改变的cron格式*/5 * * *它将在"demo"

*/2 * * 5 *

仍显示3210我怎么能克服这个?

回答

0

您正在混合使用Jquery和AngularJS,不建议使用这种方法。

您正在更新innerHTML,但如果您正在使用Angular,那不是做事情的方式。相反,你需要有ng-model,并让它更新:

<p id="demo">{{demoData}}</p> 

而在你的功能,你也应该采用了棱角分明的$http提供商:

$scope.saveCron = function(userId,scriptId,cronFormat){ 
     var data = //format your "user_id=userId&script_id=scriptId&cron=cronFormat" 
        //here inside an object 
     $http.post("updateCronChange.php", data).success(function(data){ 
      $scope.demoData = userId + scriptId + cronFormat; 
     }); 
    } 

编辑:不知道为什么你有该跨度,但为了更改cronFormat,它也应该在ng-model

我改变了它成为这个和它的作品:

<td class="cronFormat"><input type="text" ng-model="row.cron_format"/><button class="save" ng-click="saveCron(row.user_id,row.script_id,row.cron_format)">save</button></td> 

看看这个Fiddle

+0

感谢您的帮助,但仍然...它不会改变cron_format的值不更新的事实 – 2015-02-12 09:43:28

+0

@johnking对不起,错过了,看看编辑。 – 2015-02-12 09:59:29

+0

作品完美谢谢! – 2015-02-12 10:32:05