weixin_33728268 2014-04-15 04:34 采纳率: 0%
浏览 6

将结果推送到数据库

I am new to AngularJS and am trying to push the property value of an object when it is changed in my app. For instance:

List 1
<ul>
  <li ng-repeat="item in items | filter : {selected: false}">
    {{ item.name }}
    <a href="#" ng-click="move(item)">move</a>
  </li>
</ul>

List 2
<ul>
  <li ng-repeat="item in items | filter : {selected: true}">
    {{ item.name }}
    <a href="#" ng-click="move(item)">move</a>
  </li>
</ul>

So in this app, when I click "move" it changes the selected property to true or false. However in the DB this is not reflected. How can I post these as AJAX requests to achieve persistence?

  • 写回答

1条回答 默认 最新

  • csdn产品小助手 2014-04-15 05:13
    关注

    You can use $http to make an ajax call before changing the item's state. Something like...

    $scope.move = function(item) {
        var newState = !item.selected;
        $http.post(someurl, item).success(function() {
            item.selected = newState;
        });
    };
    
    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制