Angular JS 用户配置文件网格
Angular JS User Profile Grid
我在这里找到了一个我想做的例子:
http://www.bootply.com/fzLrwL73pd
看起来这个例子是使用randomUserapi生成随机用户信息和图片。我想创建与此非常相似的东西,但使用我手动输入的静态信息。我试过手动将信息输入数组,如下所示:
var myApp = angular.module('myApp', [{"user":{"gender":"female","name":{"title":"mrs","first":"taylor","last":"griffin"},"location":{"street":"2822 w 6th st","city":"everett","state":"oregon","zip":"80020"},"email":"taylor.griffin62@example.com","username":"yellowswan550","password":"twiggy","salt":"UV3zFgdW","md5":"ceb4dbcf76444647f32b059dc3fc1280","sha1":"23ae9f24c4fd1d09e12c95bd75029ea850db3fb6","sha256":"09b6a019187249e1eff7ca736865ddb6f01567dbe20774872c3115a6cbbd6ae4","registered":"1185248430","dob":"328410973","phone":"(199)-530-3414","cell":"(441)-597-7462","SSN":"961-26-7598","picture":{"large":"http://api.randomuser.me/portraits/women/82.jpg","medium":"http://api.randomuser.me/portraits/med/women/82.jpg","thumbnail":"http://api.randomuser.me/portraits/thumb/women/82.jpg"},"version":"0.5","nationality":"US"},"seed":"81aa9d006e130994"}]);
function Main(myApp){
$('#loader').hide();
$('#userList').show();
).error(function(data, status) {
alert('get data error!');
});
$scope.showUserModal = function(idx){
var user = $scope.users[idx].user;
$scope.currUser = user;
$('#myModalLabel').text(user.name.first
+ ' ' + user.name.last);
$('#myModal').modal('show');
}
}
有什么方法可以轻松地将此模板转换为更多静态内容吗?
提前感谢您的帮助!
可能有点疯狂,但如果您正在寻找更多的静态内容,是否可以窃取输出 HTML 并重新加工以满足您的需要?
看起来有点像你可以窃取以下内容:
<div class="row" id="userList">
<div ng-repeat="u in users" class="col-xs-4 col-sm-2">
<a href="" ng-click="showUserModal($index)"><img src="{{u.user.picture.large}}" class="img-thumbnail img-responsive img-circle"></a>
<h3 class="text-center">{{u.user.name.first}}</h3>
<hr>
</div>
</div>
并为每位用户手动制作您自己的 div:
<div class="row" id="userList">
<div class="col-xs-4 col-sm-2">
<a href=""><img src="/001.jpg" class="img-thumbnail img-responsive img-circle"></a>
<h3 class="text-center">User #1</h3>
<hr>
</div>
<div class="col-xs-4 col-sm-2">
<a href=""><img src="/002.jpg" class="img-thumbnail img-responsive img-circle"></a>
<h3 class="text-center">User #2</h3>
<hr>
</div>
</div>
那你可以对模态弹窗做类似的事情,当用户点击时用JS调用它们吗?
var myApp = angular.module('myApp', [{"user":{"gender":"female"..);
上面一行是错误的。模块函数的第二个参数是依赖名称。这个例子非常简单。它从 Web 服务获取数据并加载要显示的数据。如果您想静态设置它,请尝试将其设置为 $scope.users = [YOUR USER DATA]。请参阅下面的完整代码。它
var myApp = angular.module('myApp', []);
function Main($scope, $http){
$scope.users = [{"user":{"gender":"female","name":{"title":"mrs","first":"taylor","last":"griffin"},"location":{"street":"2822 w 6th st","city":"everett","state":"oregon","zip":"80020"},"email":"taylor.griffin62@example.com","username":"yellowswan550","password":"twiggy","salt":"UV3zFgdW","md5":"ceb4dbcf76444647f32b059dc3fc1280","sha1":"23ae9f24c4fd1d09e12c95bd75029ea850db3fb6","sha256":"09b6a019187249e1eff7ca736865ddb6f01567dbe20774872c3115a6cbbd6ae4","registered":"1185248430","dob":"328410973","phone":"(199)-530-3414","cell":"(441)-597-7462","SSN":"961-26-7598","picture":{"large":"http://api.randomuser.me/portraits/women/82.jpg","medium":"http://api.randomuser.me/portraits/med/women/82.jpg","thumbnail":"http://api.randomuser.me/portraits/thumb/women/82.jpg"},"version":"0.5","nationality":"US"},"seed":"81aa9d006e130994"}];
$('#loader').hide();
$('#userList').show();
$scope.showUserModal = function(idx){
var user = $scope.users[idx].user;
$scope.currUser = user;
$('#myModalLabel').text(user.name.first
+ ' ' + user.name.last);
$('#myModal').modal('show');
}
}
感谢您的所有回答;但是,我想我终于明白了!
在bootstrap中有一个叫做模态的东西(getboostrap.com/javascript)。我只是使用带有图像的模式而不是按钮。我什至能够使用上面示例中模态的部分布局:
<!-- image trigger modal -->
<a href="#" data-toggle="modal" data-target="#testModal">
<img class="img-responsive staffimg" src="images/profile.png">
</a>
<div id="testModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="testLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header bg-info">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h1 id="testLabel" class="text-center"></h1>
</div>
<div class="modal-body">
<div class="container-fluid">
<div class="row">
<div class="col-xs-4 col-xs-offset-4"><img src="images/profile.png" class="img-thumbnail img-responsive img-circle"></div>
</div>
<hr>
<div class="row">
<h4 class="text-center"><i class="fa fa-fw fa-phone fa-2x"></i> Phone: 555-555-5555 ect 555</h4>
<h4 class="text-center"><i class="fa fa-fw fa-envelope-o fa-2x"></i> Email:<a href="mailto:test@gmail.com> test@gmail.com</a></h4>
<h4 class="text-center"><i class="fa fa-fw fa-user fa-2x"></i> penguins66</h4>
</div>
</div>
</div>
<div class="modal-footer bg-info">
<button class="btn btn-lg btn-default center-block" data-dismiss="modal" aria-hidden="true">Okay!</button>
</div>
</div>
</div>
</div><!--/modal-->
我在这里找到了一个我想做的例子:
http://www.bootply.com/fzLrwL73pd
看起来这个例子是使用randomUserapi生成随机用户信息和图片。我想创建与此非常相似的东西,但使用我手动输入的静态信息。我试过手动将信息输入数组,如下所示:
var myApp = angular.module('myApp', [{"user":{"gender":"female","name":{"title":"mrs","first":"taylor","last":"griffin"},"location":{"street":"2822 w 6th st","city":"everett","state":"oregon","zip":"80020"},"email":"taylor.griffin62@example.com","username":"yellowswan550","password":"twiggy","salt":"UV3zFgdW","md5":"ceb4dbcf76444647f32b059dc3fc1280","sha1":"23ae9f24c4fd1d09e12c95bd75029ea850db3fb6","sha256":"09b6a019187249e1eff7ca736865ddb6f01567dbe20774872c3115a6cbbd6ae4","registered":"1185248430","dob":"328410973","phone":"(199)-530-3414","cell":"(441)-597-7462","SSN":"961-26-7598","picture":{"large":"http://api.randomuser.me/portraits/women/82.jpg","medium":"http://api.randomuser.me/portraits/med/women/82.jpg","thumbnail":"http://api.randomuser.me/portraits/thumb/women/82.jpg"},"version":"0.5","nationality":"US"},"seed":"81aa9d006e130994"}]);
function Main(myApp){
$('#loader').hide();
$('#userList').show();
).error(function(data, status) {
alert('get data error!');
});
$scope.showUserModal = function(idx){
var user = $scope.users[idx].user;
$scope.currUser = user;
$('#myModalLabel').text(user.name.first
+ ' ' + user.name.last);
$('#myModal').modal('show');
}
}
有什么方法可以轻松地将此模板转换为更多静态内容吗?
提前感谢您的帮助!
可能有点疯狂,但如果您正在寻找更多的静态内容,是否可以窃取输出 HTML 并重新加工以满足您的需要?
看起来有点像你可以窃取以下内容:
<div class="row" id="userList">
<div ng-repeat="u in users" class="col-xs-4 col-sm-2">
<a href="" ng-click="showUserModal($index)"><img src="{{u.user.picture.large}}" class="img-thumbnail img-responsive img-circle"></a>
<h3 class="text-center">{{u.user.name.first}}</h3>
<hr>
</div>
</div>
并为每位用户手动制作您自己的 div:
<div class="row" id="userList">
<div class="col-xs-4 col-sm-2">
<a href=""><img src="/001.jpg" class="img-thumbnail img-responsive img-circle"></a>
<h3 class="text-center">User #1</h3>
<hr>
</div>
<div class="col-xs-4 col-sm-2">
<a href=""><img src="/002.jpg" class="img-thumbnail img-responsive img-circle"></a>
<h3 class="text-center">User #2</h3>
<hr>
</div>
</div>
那你可以对模态弹窗做类似的事情,当用户点击时用JS调用它们吗?
var myApp = angular.module('myApp', [{"user":{"gender":"female"..); 上面一行是错误的。模块函数的第二个参数是依赖名称。这个例子非常简单。它从 Web 服务获取数据并加载要显示的数据。如果您想静态设置它,请尝试将其设置为 $scope.users = [YOUR USER DATA]。请参阅下面的完整代码。它
var myApp = angular.module('myApp', []);
function Main($scope, $http){
$scope.users = [{"user":{"gender":"female","name":{"title":"mrs","first":"taylor","last":"griffin"},"location":{"street":"2822 w 6th st","city":"everett","state":"oregon","zip":"80020"},"email":"taylor.griffin62@example.com","username":"yellowswan550","password":"twiggy","salt":"UV3zFgdW","md5":"ceb4dbcf76444647f32b059dc3fc1280","sha1":"23ae9f24c4fd1d09e12c95bd75029ea850db3fb6","sha256":"09b6a019187249e1eff7ca736865ddb6f01567dbe20774872c3115a6cbbd6ae4","registered":"1185248430","dob":"328410973","phone":"(199)-530-3414","cell":"(441)-597-7462","SSN":"961-26-7598","picture":{"large":"http://api.randomuser.me/portraits/women/82.jpg","medium":"http://api.randomuser.me/portraits/med/women/82.jpg","thumbnail":"http://api.randomuser.me/portraits/thumb/women/82.jpg"},"version":"0.5","nationality":"US"},"seed":"81aa9d006e130994"}];
$('#loader').hide();
$('#userList').show();
$scope.showUserModal = function(idx){
var user = $scope.users[idx].user;
$scope.currUser = user;
$('#myModalLabel').text(user.name.first
+ ' ' + user.name.last);
$('#myModal').modal('show');
}
}
感谢您的所有回答;但是,我想我终于明白了!
在bootstrap中有一个叫做模态的东西(getboostrap.com/javascript)。我只是使用带有图像的模式而不是按钮。我什至能够使用上面示例中模态的部分布局:
<!-- image trigger modal -->
<a href="#" data-toggle="modal" data-target="#testModal">
<img class="img-responsive staffimg" src="images/profile.png">
</a>
<div id="testModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="testLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header bg-info">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h1 id="testLabel" class="text-center"></h1>
</div>
<div class="modal-body">
<div class="container-fluid">
<div class="row">
<div class="col-xs-4 col-xs-offset-4"><img src="images/profile.png" class="img-thumbnail img-responsive img-circle"></div>
</div>
<hr>
<div class="row">
<h4 class="text-center"><i class="fa fa-fw fa-phone fa-2x"></i> Phone: 555-555-5555 ect 555</h4>
<h4 class="text-center"><i class="fa fa-fw fa-envelope-o fa-2x"></i> Email:<a href="mailto:test@gmail.com> test@gmail.com</a></h4>
<h4 class="text-center"><i class="fa fa-fw fa-user fa-2x"></i> penguins66</h4>
</div>
</div>
</div>
<div class="modal-footer bg-info">
<button class="btn btn-lg btn-default center-block" data-dismiss="modal" aria-hidden="true">Okay!</button>
</div>
</div>
</div>
</div><!--/modal-->