我试图以适当的方式做到这一点,减少痛苦,但我无法弄清楚如何处理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?为什么?
什么是适当的方式,减少疼痛?
使用这个宝石 https://github.com/sinisterchipmunk/gravatar 我如何检查指定电子邮件的gravatar是否存在?我想我错过了一些强制默认选项?因为这
url = Gravatar.new("generic@example.com").image_url
Run Code Online (Sandbox Code Playgroud)
总是回来一张照片
让我说我的角度应用程序周围有几个$资源和一些$ 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?
在 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) 我使用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调用里面如下:
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) 摔跤我的头脑模型跟随
我最终会跟随,但我仍然相信,必须有更好的解决方案.
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) 有没有一种简单的方法可以将选项作为数组中的对象?如下:
$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)
或者我完全错了?
我想在ministest中禁用use_transactional_fixtures = false来捕获after_commit回调.我应该在什么地方和哪里设置?
我正在使用标准设置部署rails4应用程序,但获得:
此应用程序是Rails 4应用程序,但它被错误地检测为Rails 1或Rails 2应用程序.这可能是Phusion Passenger中的一个错误,所以请报告.
angularjs ×5
javascript ×3
http ×2
activeadmin ×1
angular-ui ×1
apiary.io ×1
base64 ×1
callback ×1
checkbox ×1
deflate ×1
gravatar ×1
http-headers ×1
json ×1
minitest ×1
model ×1
nginx ×1
passenger ×1
repeat ×1
sql-order-by ×1