【问题标题】:Angularfire $save arrayAngularfire $保存数组
【发布时间】:2014-10-28 15:39:07
【问题描述】:

在我更新了数组中的一个条目后,我正在尝试保存一组数据。

    // Edit a post
$scope.editMe = function(message) {
  if($scope.textBoxMessage = "What good did you do today?"){
    $scope.textBoxMessage = "Here you can edit your post by entering a new message and pressing edit on the affected post" + "\n \n" + "Your post:" + "\n" + message.post;
  }
  else{
    $scope.message.post="hello"; //$scope.newMessage
    $scope.messages.$save(2);

  }
}

用户在文本字段中输入了一些文本,我想用已经存储的数据替换它。这是通过用一些文本覆盖 message.data 来实现的。因为我读到这样的数据:

var list = fbutil.syncArray('posts/'+user.uid);

我也试着简单地说:

message.post = $scope.newMessage;
list.$save()

这两种方法都不起作用,但我确信这是一个小错误。

ED: 根据angularFire api,访问:https://www.firebase.com/docs/web/libraries/angular/api.html#angularfire-firebasearray-save-recordorindex

    list[2].post = "hello";
    list.$save(2);

应该工作,但我没有运气。

【问题讨论】:

  • 声明 if($scope.textBoxMessage = "hi") 将始终是真实的(不是 true),因为您正在分配一个值,而不是比较值。要比较值,请使用 == 而不是赋值运算符。
  • 是的,这也是真的,我对那个不好。

标签: angularjs firebase angularfire


【解决方案1】:

好的,这就是我的解决方法:

问题更多与 if else 语句有关,然后与服务器代码本身有关。无论如何, $scope.textBoxMessage 总是正确的,这让我感到困扰。即使我说 if($scope.textBoxMessage = "hi") 也是如此。

我不确定为什么会这样,但如果您有任何建议,请随时发表评论。

我就是这样解决的:

    // Edit a post
$scope.editMe = function(message) {
  if($scope.newMessage == null){
    $scope.textBoxMessage = "Here you can edit your post by entering a new message and pressing edit on the affected post" + "\n \n" + "Your post:" + "\n" + message.post;
  }
  else{
    message.post = $scope.newMessage;
    list.$save(message);
    $scope.textBoxMessage = chatmessage;
    $scope.newMessage = null;
  }
}

【讨论】:

    猜你喜欢
    • 2019-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-17
    • 2022-08-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多