小编Jak*_*har的帖子

AngularJS复选框重复和选定的对象?

我试图以适当的方式做到这一点,减少痛苦,但我无法弄清楚如何处理ng模型并将其绑定到选定的列表等,而且我需要在以后填充该列表并保持选定的对象在里面.

categories = [ { "name": "Sport", "id": "50d5ad" } , {"name": "General", "id": "678ffr" } ]

    <span ng-repeat="category in categories">
      <label class="checkbox" for="{{category.id}}">
        <input type="checkbox" value="{{category.id}}" ng-model="??" ng-click="??" name="group" id="{{category.id}}" />
        {{category.name}}
      </label>
    </span>
Run Code Online (Sandbox Code Playgroud)

每次填充列表时我都必须覆盖类别,因为它将从服务器中提取出来.

所以我想我需要有数组,第二个将保存所选对象?

如果我是对的,我该如何预选复选框?

我是否需要按-n键才能调用自定义函数将所选对象存储在另一个数组中?

我在复选框中是否需要ng-model?为什么?

什么是适当的方式,减少疼痛?

javascript checkbox repeat angularjs

40
推荐指数
1
解决办法
8万
查看次数

我该如何检查是否存在gravatar?

使用这个宝石 https://github.com/sinisterchipmunk/gravatar 我如何检查指定电子邮件的gravatar是否存在?我想我错过了一些强制默认选项?因为这

url = Gravatar.new("generic@example.com").image_url
Run Code Online (Sandbox Code Playgroud)

总是回来一张照片

gravatar ruby-on-rails

8
推荐指数
2
解决办法
5173
查看次数

AngularJS - 如何对所有jsons请求进行deflate和编码/解码到base64?

让我说我的角度应用程序周围有几个$资源和一些$ http:

myApp.factory('Note', function($resource) {

  return $resource('http://', {id: '@id'}, 
    { 'index': { method: 'GET', isArray: true },
      'update': { method: 'PUT'},
    });
  });
Run Code Online (Sandbox Code Playgroud)

与控制器

myApp.controller('NotesController',function NotesController($scope, Note, AuthenticationService) {

$scope.notes = Note.index({}, function(data){
    console.log('success, got data: ', data);
    $scope.response = "yoy!"
  }, function(err){
    console.log('error, got data: ', err);
    $scope.response = "yay!"
  }); 
});
Run Code Online (Sandbox Code Playgroud)

并且一些请求由$ http直接进行,如身份验证

var request = $http.post('http://', {email: email, password: password});
Run Code Online (Sandbox Code Playgroud)

在实际请求发出/响应接收之前,我可以在何处以及如何判断角度以对JSON进行收缩和编码/解码?

我想我将外部库包装为deflate并编码/解码到工厂.然后这个工厂将被注入?喜欢$ httpBackend?

base64 json http deflate angularjs

8
推荐指数
1
解决办法
5万
查看次数

Rails Active Admin 如何使用 2 列(来自关联的 1 列)进行 config.sort_order

在 Active Admin 中,想知道如何使用 2 列设置 config.sort_order,其中第一列来自同一模型,第二列来自关联模型?

ActiveAdmin.register Race do
  menu parent: :races, :label => proc{ I18n.t('activerecord.models.races') }
  belongs_to :meeting, :optional => true
  #need to order by "meetings.date desc races.time desc"
  config.sort_order = "?"



  controller do
    def scoped_collection
      end_of_association_chain.includes(:meeting)
    end
  end

end
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails sql-order-by activeadmin

5
推荐指数
1
解决办法
1920
查看次数

AngularJS和Apiary.IO - 无法读取任何响应标头?

我使用Apiary.io模拟我的API.但不知怎的,我无法使用angularJS从响应对象中读取任何标头.而且我确信我至少通过检查firebug来正确设置Content-Type:application/json.Angular中的代码也应正确读取标题,因为我可以在向apiary.io发送请求时将其打印出来...

  $http.get('http://ies.apiary.io/some').then(function(response) {  
    console.log("ok",response.headers('Content-Type'));
    },function(response){console.log("err",response);});
Run Code Online (Sandbox Code Playgroud)

http://plnkr.co/edit/zMO0pXGsIdJkV0fZdBdw

javascript http-headers angularjs apiary.io

4
推荐指数
1
解决办法
4892
查看次数

当响应准备就绪时,我应该关注带有$ http调用的AngularJS工厂吗?

我有类似的工厂与$ http调用里面如下:

appModule = angular.module('appModule', []);

appModule.factory('Search', function($rootScope, $http) {
  var Search;
  Search = {};
  Search.types: ["bacon"];
  Search.pastEvents = null;
  $http.get('api/highlights').success(function(response) {
    return Search.pastEvents = response.data;
  });
  return Search;
});

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

notes_module.config(['$routeProvider', function ($routeProvider) {

  var notes_promise = ['Notes', '$route', 'Search', function (Notes, $route, Search) {
    //suspect that Search not having pastEvents ready in time of calling index method
    //Notes resource  
    return Notes.index({subject_id: 1 }, Search);    
  }];

  $routeProvider.when('/notes', {
    templateUrl:'index.tpl.html',
    controller:'NotesCtrl',
    resolve:{
      notes: notes_promise,
    }
  }); …
Run Code Online (Sandbox Code Playgroud)

http callback angularjs

4
推荐指数
1
解决办法
6846
查看次数

您如何使用自引用和类别对联系人列表进行建模?

摔跤我的头脑模型跟随

  1. 用户有很多联系人类别(家人/朋友)
  2. 一个联系人类别有很多联系人
  3. 一个联系人可以是一个或多个联系人类别.

我最终会跟随,但我仍然相信,必须有更好的解决方案.

class User < ActiveRecord::Base  
    has_many :contact_groups  

    def get_all_contacts  
        self.contact_groups.each do |group|  
        contacts << group.users  
    end  
end  

class ContactGroup < ActiveRecord::Base  
    has_and_belongs_to_many :users  
end 
Run Code Online (Sandbox Code Playgroud)

model ruby-on-rails self-reference

3
推荐指数
1
解决办法
2007
查看次数

有对象的Angular UI select2数组有可能吗?

有没有一种简单的方法可以将选项作为数组中的对象?如下:

$scope.search.categories = [{id: '1',name: 'first'},{id: '2',name: 'last'}];

<select ui-select2 ng-model="search.categories" multiple style="width:300px" data-placeholder="select category">
  <option ng-repeat="category in search.categories" value="{{category}}">{{category.name}}</option>

</select>
Run Code Online (Sandbox Code Playgroud)

或者我完全错了?

javascript angularjs jquery-select2 angular-ui

2
推荐指数
1
解决办法
7929
查看次数

Rails minitest,数据库更清洁如何转为use_transactional_fixtures = false

我想在ministest中禁用use_transactional_fixtures = false来捕获after_commit回调.我应该在什么地方和哪里设置?

ruby-on-rails minitest database-cleaner

2
推荐指数
1
解决办法
2411
查看次数

Rails4,passenger,nginx(应用程序是rails4但错误地检测为Rails1或Rails2)

我正在使用标准设置部署rails4应用程序,但获得:

此应用程序是Rails 4应用程序,但它被错误地检测为Rails 1或Rails 2应用程序.这可能是Phusion Passenger中的一个错误,所以请报告.

http://ec2-54-187-113-154.us-west-2.compute.amazonaws.com/

passenger nginx ruby-on-rails-4

0
推荐指数
1
解决办法
403
查看次数