我有一个JSON文件,其中包含我想在AngularJS网站上访问的一些数据.现在我想要的是从数组中只获取一个对象.所以我想要例如ID为1的Item.
数据如下所示:
{ "results": [
{
"id": 1,
"name": "Test"
},
{
"id": 2,
"name": "Beispiel"
},
{
"id": 3,
"name": "Sample"
}
] }
Run Code Online (Sandbox Code Playgroud)
我想用AngularJS $ http功能加载数据,如下所示:
$http.get("data/SampleData.json");
这是有效的.但是,我现在如何从我得到的数组中获取特定的数据对象(通过id)$http.get?
在此先感谢您的帮助.
迎接马克
我目前正在开发REST + AngularJS应用程序.
关于资源保存行动的承诺我有一点问题.
我的工厂:
App.factory('Course', function($resource) {
var course = $resource('/AppServer/admin/courses/:courseId', {}, {});
course.findAll = function() {
return course.query();
};
course.findById = function(id) {
return course.get({
courseId : id
});
};
course.saveCourse = function(course) {
return course.$save();
}
return course;
});
Run Code Online (Sandbox Code Playgroud)
我的控制器:
App.controller('CourseEditController', function($scope, $routeParams, $location, Course, FlashMessage) {
// load course into edit form
$scope.course = Course.findById($routeParams.courseId);
// save edited course and print flash message
$scope.saveCourse = function() {
var savedCourse = Course.saveCourse($scope.course);
savedCourse.$then(function(httpResponse) {
FlashMessage.set("Die Änderungen am …Run Code Online (Sandbox Code Playgroud) 我有一个带有controllers.js和factories.js的AngularJS应用程序.
我喜欢的是用控制器中的值(我从工厂获得)做一些事情.我的问题是,在我访问它们时这些值是空的.
我怎么能等待回复?或者我在哪里可以添加回调?
Flashcards.controller('CardDeckDetailController', function($scope, $routeParams, CardDeckService, CardService) {
$scope.carddeck = CardDeckService.findCardDeckByID($routeParams.cardDeckID);
$scope.cards = CardService.findCardsByCardDeckID($routeParams.cardDeckID);
$scope.card = $scope.cards[0];
$scope.cardLength = $scope.cards.length;
});
Flashcards.factory('CardDeckService', function($resource) {
var cardDeckService = $resource('/FlashcardsServer/rest/carddecks/:cardDeckID', {}, {});
cardDeckService.findAllCardDecks = function() {
return cardDeckService.query();
};
cardDeckService.findCardDeckByID = function(id) {
return cardDeckService.get({ cardDeckID : id });
};
return cardDeckService;
});
Run Code Online (Sandbox Code Playgroud)
我喜欢的是获得第一辆车($ scope.cards [0])并将其保存在$ scope.card下.但它总是空的(与cardsLength相同).
另一方面,如果我使用(cards.length)从局部视图中打印出大小,我会得到正确的值.
迎接并感谢Marc
我有一个带有Jersey Backend应用程序的AngularJS web应用程序.
现在一切正常,使用ngResource从AngularJS中访问REST资源.唯一的问题是DELETE选项.
我有以下代码使用我的ngResource删除课程:
Course.deleteCourse = function(course) {
course.$remove({
courseId:course.id
});
return course;
};
Run Code Online (Sandbox Code Playgroud)
在后端(泽西岛),我有以下代码:
@DELETE
@Path("{id}")
public final void remove(@PathParam("id") final String id) {
System.out.println("DELETE ID = " + id);
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试删除项目,则从Angular调用以下URL:
DELETE http://localhost:8080/manager-api/courses/5
Run Code Online (Sandbox Code Playgroud)
这很好(在我之后).如果我从CURL调用此URL,我会将后端的ssystem.out发布到控制台.
在客户端应用程序(AngularJS)中,我在浏览器控制台上收到以下异常:
DELETE http://localhost:8080/manager-api/courses/5 415 (Unsupported Media Type)
Run Code Online (Sandbox Code Playgroud)
谁知道问题可能是什么?POST + GET工作正常.
我有以下消费/产生注释:
@Consumes({ MediaType.APPLICATION_JSON })
Run Code Online (Sandbox Code Playgroud)
@Produces({MediaType.APPLICATION_JSON})
在此先感谢您的帮助.
迎接马克
编辑:
我试图用$ http替换AngularJS中访问REST服务的方式.
现在我的服务如下:
MyApp.factory("Course", ["$http", function ($http) {
var courseBaseUrl = "/api/courses/";
return {
show: function show(courseId) {
return $http.get(courseBaseUrl + courseId);
},
list: function …Run Code Online (Sandbox Code Playgroud) 我有一个 Spring Boot 应用程序,我想使用应用程序引擎 maven 插件将其部署在 Google 应用程序引擎上。
一切正常,除了我找不到 Google 应用引擎为 Spring Boot 应用加载正确的 application.properties 文件的方法。
我有 application-prod.properties、application-default.properties 和 application-test.properties。例如,在本地我可以轻松选择要开始使用的环境/配置文件
mvn appengine:run -Dspring.profiles.active=prod
Run Code Online (Sandbox Code Playgroud)
但是当我尝试为部署工作做同样的事情时,比如
mvn appengine:deploy -Dspring.profiles.active=prod
Run Code Online (Sandbox Code Playgroud)
那行不通。它不会加载 application-prod.properties 而是回退到 application-default.properties。
我是否误解了某些东西,或者应该这样做吗?如果这不起作用,因为谷歌应用引擎只是在没有传递任何参数的情况下开始战争,有没有办法为谷歌上的应用程序/服务定义环境变量,我可以在其中存储诸如数据库url和特定于环境的凭据之类的东西?
谢谢你们的帮助。
我喜欢使用CSS伪元素在DIV之前添加图标.我为此创建了一个JS小提琴.问题是,before伪元素不占用整个高度.我想它与div的高度相同.目前它只需要图标所需的高度.
<div class="icon"><p>Lorem Ipsum...</p><p>Lorem Ipsum...</p><p>Lorem Ipsum...</p><div>
Run Code Online (Sandbox Code Playgroud)
http://jsfiddle.net/marcbaur/veq13ohs/
是否有人知道如何解决这个问题?
电贺
我刚刚设置了我的新 Macbook Pro 15" (2017)。在安装和配置我的 Virtualbox VM 的过程中,我意识到“启用 VT-x/AMD-V”选项可以在虚拟机设置 - 系统 - 下找到加速在我的新 Macbook Pro 上不可用,而在我之前的 Macbook Pro 15" 2014 上可用。你有什么想法可能是什么原因吗?两台 Macbook 都在 macOS Sierra 10.12.6 下运行,并且都安装了最新版本的 VirtualBox。由于我在 VM 中做了很多工作,我很高兴能够启用此选项。
如果有人可以帮助我,我将不胜感激。
问候
我有一个泽西休息应用程序,我喜欢使用AngularJS应用程序访问.
我已经将资源定义如下:
服务:
angular.service('Wine', function ($resource) {
return $resource('/myserver/rest/wines/:wineId', {}, {
update: {method:'PUT'},
'query': {method: 'GET', isArray: true}
});
});
Run Code Online (Sandbox Code Playgroud)
控制器:
function WineListCtrl(Wine) {
this.wines = Wine.query();
}
Run Code Online (Sandbox Code Playgroud)
在Firebug中,我可以看到此GET-Request的结果:
{"wine":[{"country":"USA","description":"With hints of ginger and spice, this wine makes an excellent complement to light appetizer and dessert fare for a holiday gathering.","grapes":"Pinot Noir","id":"9","name":"BLOCK NINE","picture":"block_nine.jpg","region":"California","year":"2009"},{"country":"Argentina","description":"Solid notes of black currant blended with a light citrus make this wine an easy pour for varied palates.","grapes":"Pinot Gris","id":"11","name":"BODEGA LURTON","picture":"bodega_lurton.jpg","region":"Mendoza","year":"2011"},{"country":"France","description":"The aromas of fruit and spice give one …Run Code Online (Sandbox Code Playgroud)