- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
这个命令...即,
$http.get('http://localhost:8084/nggridtest/tasks')
.success(function (data)
{
alert(JSON.stringify(data));
$scope.tasks = data; // <=== not working???
});
...似乎已成功检索数据 - 如我的警报所示...即
但是,命令 - $scope.tasks = data;
- 似乎没有将数据分配给我的“$scope.tasks”变量 - 导致一个空网格......即,
我在这里做错了什么?
感谢您的帮助!!
(AngularJS纽比)
<小时/>如果需要,下面是更多信息...
<小时/>app.js
/* global angular */
var taskApp = angular.module('taskApp', ['ngGrid']);
var taskController = taskApp.controller('taskController', function taskController($scope, $http)
{
$http.get('http://localhost:8084/nggridtest/tasks')
.success(function (data)
{
alert(JSON.stringify(data));
$scope.tasks = data;
});
$scope.gridOptions = {
data: 'tasks',
columnDefs: [
{field: 'taskId', displayName: 'taskId'},
{field: 'taskName', displayName: 'taskName'},
{field: 'taskDescription', displayName: 'taskDescription'},
{field: 'taskStartTime', displayName: 'taskStartTime'},
{field: 'taskEndTime', displayName: 'taskEndTime'},
{field: 'taskArchived', displayName: 'taskArchived'}
]
};
});
app.css
.gridStyle
{
margin: 0;
width:100em;
height:50em;
}
index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!doctype html>
<html ng-app="taskApp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Spring MVC, REST, AngularJS testing</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/webjars/jquery/2.1.4/jquery.css" media="screen">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/webjars/ng-grid/2.0.14/ng-grid.css" media="screen">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/webjars/bootstrap/3.3.1/css/bootstrap.css" media="screen">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/resources/js/app.css" media="screen"/>
<script type="text/javascript" src="${pageContext.request.contextPath}/webjars/jquery/2.1.4/jquery.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/webjars/angularjs/1.4.4/angular.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/webjars/ng-grid/2.0.14/ng-grid.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/webjars/bootstrap/3.3.1/js/bootstrap.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/js/app.js"></script>
</head>
<body>
<div ng-controller="taskController">
<div class='panel panel-primary row container-fluid' style="margin: 2em; padding:0;">
<div class='panel-heading' style="margin: 0;">
<h1 class='panel-title'>Entries</h1>
</div>
<div class='panel-body' style="padding:0;">
<div class="gridStyle" ng-grid="gridOptions"></div>
</div>
</div>
</div>
</body>
</html>
TaskController.java
package aaa.bbb.ccc.war;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@RestController
@EnableWebMvc
public class TaskController
{
private static final org.apache.logging.log4j.Logger LOG = LogManager.getLogger("TaskController");
TaskService taskmanagerservice = new TaskService();
@RequestMapping(value = "/tasks", method = RequestMethod.GET, headers = "Accept=application/json")
public List<Task> getAllTasks()
{
List<Task> tasks = null;
try
{
tasks = taskmanagerservice.getAllTasks();
}
catch (Exception e)
{
LOG.error("____________________________getAllTasks____________________________Exception encountered - e.getMessage=" + e.getMessage(), e);
}
return tasks;
}
}
TaskService.java
package aaa.bbb.ccc.war;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import org.apache.logging.log4j.LogManager;
public class TaskService
{
private static final org.apache.logging.log4j.Logger LOG = LogManager.getLogger("TaskService");
private Connection connection;
public TaskService()
{
connection = DBUtility.getConnection();
}
public List<Task> getAllTasks()
{
List<Task> tasks = null;
try
{
tasks = new ArrayList<Task>();
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery("select * from task_list where task_archived=false");
while (rs.next())
{
Task task = new Task();
task.setTaskId(rs.getInt("task_id"));
task.setTaskName(rs.getString("task_name"));
task.setTaskDescription(rs.getString("task_description"));
task.setTaskPriority(rs.getString("task_priority"));
task.setTaskStatus(rs.getString("task_status"));
tasks.add(task);
}
}
catch (SQLException e)
{
LOG.error("____________________________getAllTasks____________________________Exception encountered - e.getMessage=" + e.getMessage(), e);
}
return tasks;
}
}
DBUtility
package aaa.bbb.ccc.war;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
import org.apache.logging.log4j.LogManager;
public class DBUtility
{
private static final org.apache.logging.log4j.Logger LOG = LogManager.getLogger("DBUtility");
private static Connection connection = null;
public static Connection getConnection()
{
if (connection != null)
{
return connection;
}
else
{
try
{
Properties prop = new Properties();
InputStream inputStream = DBUtility.class.getClassLoader().getResourceAsStream("/config.properties");
prop.load(inputStream);
String driver = prop.getProperty("driver");
String url = prop.getProperty("url");
String user = prop.getProperty("user");
String password = prop.getProperty("password");
Class.forName(driver);
connection = DriverManager.getConnection(url, user, password);
}
catch (ClassNotFoundException e)
{
LOG.error("____________________________getConnection____________________________ClassNotFoundException", e);
}
catch (SQLException e)
{
LOG.error("____________________________getConnection____________________________SQLException", e);
}
catch (FileNotFoundException e)
{
LOG.error("____________________________getConnection____________________________FileNotFoundException", e);
}
catch (IOException e)
{
LOG.error("____________________________getConnection____________________________IOException", e);
}
return connection;
}
}
}
Task.java
package aaa.bbb.ccc.war;
public class Task
{
private int task_id;
private String task_name;
private String task_description;
private String task_priority;
private String task_status;
public int getTaskId()
{
return task_id;
}
public void setTaskId(int taskId)
{
this.task_id = taskId;
}
public String getTaskName()
{
return task_name;
}
public void setTaskName(String taskName)
{
this.task_name = taskName;
}
public String getTaskDescription()
{
return task_description;
}
public void setTaskDescription(String taskDescription)
{
this.task_description = taskDescription;
}
public String getTaskPriority()
{
return task_priority;
}
public void setTaskPriority(String taskPriority)
{
this.task_priority = taskPriority;
}
public String getTaskStatus()
{
return task_status;
}
public void setTaskStatus(String taskStatus)
{
this.task_status = taskStatus;
}
@Override
public String toString()
{
return "Task{" + "task_id=" + task_id + ", task_name=" + task_name + ", task_description=" + task_description + ", task_priority=" + task_priority + ", task_status=" + task_status + '}';
}
}
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="aaa.bbb.ccc.war" />
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
</mvc:message-converters>
</mvc:annotation-driven>
<mvc:default-servlet-handler/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<mvc:resources mapping="/static/**" location="/static/" />
<mvc:resources mapping="/webjars/**" location="/webjars/" />
<mvc:resources mapping="/assets/**" location="/assets/" />
<mvc:resources mapping="/resources/**" location="/resources/" />
</beans>
web.xml
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<filter>
<filter-name>charEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>charEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
WEB-INF/spring/applicationContext.xml
</param-value>
</context-param>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
WEB-INF/spring/applicationContext.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
config.properties
driver=org.apache.derby.jdbc.ClientDriver
url=jdbc:derby://localhost:1527/taskmanager
user=app
password=app
log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="testLogEvent" packages="">
<Appenders>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%-7p %d [%t] %c %x - %m%n"/>
</Console>
<!-- writes log file to the tomee "logs" folder... -->
<File name="appLog" fileName="../logs/nggridtest.log">
<PatternLayout>
<Pattern>%-7p %d [%t] %c %x - %m%n</Pattern>
</PatternLayout>
</File>
<Async name="Async">
<AppenderRef ref="appLog"/>
</Async>
</Appenders>
<Loggers>
<Root level="DEBUG">
<AppenderRef ref="STDOUT"/>
<AppenderRef ref="Async"/>
</Root>
</Loggers>
</Configuration>
使用了 derby 数据库
CREATE TABLE "TASK_LIST"
(
"TASK_ID" INT not null primary key GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
"TASK_NAME" VARCHAR(50),
"TASK_DESCRIPTION" VARCHAR(50),
"TASK_PRIORITY" VARCHAR(100),
"TASK_STATUS" VARCHAR(20),
"TASK_START_TIME" TIMESTAMP,
"TASK_END_TIME" TIMESTAMP,
"TASK_ARCHIVED" BOOLEAN
);
//...NOTE: the task_id column value is auto-generated...
insert into task_list (task_name, task_description, task_priority, task_status, task_start_time, task_end_time, task_archived) values('Gathering Requirement', 'Requirement Gathering', 'MEDIUM', 'ACTIVE', CURRENT TIMESTAMP, {fn TIMESTAMPADD(SQL_TSI_HOUR, 1, CURRENT_TIMESTAMP)}, false);
insert into task_list (task_name, task_description, task_priority, task_status, task_start_time, task_end_time, task_archived) values('Application Designing', 'Application Designing', 'MEDIUM', 'ACTIVE', CURRENT TIMESTAMP, {fn TIMESTAMPADD(SQL_TSI_HOUR, 2, CURRENT_TIMESTAMP)}, false);
insert into task_list (task_name, task_description, task_priority, task_status, task_start_time, task_end_time, task_archived) values('Implementation', 'Implementation', 'MEDIUM', 'ACTIVE', CURRENT TIMESTAMP, {fn TIMESTAMPADD(SQL_TSI_HOUR, 3, CURRENT_TIMESTAMP)}, false);
insert into task_list (task_name, task_description, task_priority, task_status, task_start_time, task_end_time, task_archived) values('Unit Testing', 'Unit Testing', 'LOW', 'ACTIVE', CURRENT TIMESTAMP, {fn TIMESTAMPADD(SQL_TSI_HOUR, 4, CURRENT_TIMESTAMP)}, false);
insert into task_list (task_name, task_description, task_priority, task_status, task_start_time, task_end_time, task_archived) values('Maintenance', 'Maintenance', 'LOW', 'ACTIVE', CURRENT TIMESTAMP, {fn TIMESTAMPADD(SQL_TSI_HOUR, 5, CURRENT_TIMESTAMP)}, false);
项目结构
最佳答案
正如 Lrossy 提到的,该对象可能尚未定义。因此,在 Controller 或链接函数的开头(在获取请求之前),定义它:
$scope.tasks = []
那么,也许需要插入才能应用范围?不太可能,因为 $http 知道这样做,但将其放入您的成功处理程序中可能会有所帮助:
if (!$scope.$$phase) {
$scope.$apply();
}
关于javascript - 为什么我的 gridOptions (ng-grid) 中的 "data"参数始终为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33310381/
我必须使用 gridExtra::grid.arrange 来绘制除彼此之外的多个图,因为我使用该包来创建图的拟合。 我必须使用 grid.arrange 为绘图创建一个标题。 现在我想将两者结合起来
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 4年前关闭。 Improve t
在我的农业网格的每一行中。我需要在每一行 ag-grid 中添加 Angular Material 图标按钮。但是,结果只显示了文本按钮。它不会在我的农业网格中显示我的图标按钮。 接下来,我需要在我的
我正在尝试使用 JSON 数据填充 KendoUI 网格,其中服务器返回总行数以及数据,但是我在让 serverPaging 正常工作时遇到了一些问题。我创建并分配网格的数据源如下:
Kendo 网格在网格加载、分页、排序时自动提供自己的加载指示器。它工作正常。 但我不希望显示/隐藏此内置加载指示器。 如何禁用此功能? 请建议我。 谢谢, 维诺特 最佳答案 很简单,只需用 CSS
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 11 年前。 Improve thi
我正在尝试将noDataMessage设置为dojox.grid.EnhancedGrid,网格工作正常,当商店获取数据时它显示它是行,没有问题,但是我需要当商店没有数据时网格将向我显示个性化消息。我
我的 ExtJS 6 框架有问题。当我使用 Ext.grid.Panel 时它可以工作,但我想使用 Ext.grid.Grid 。 Ext.grid.Panel 和 Ext.grid.Grid 有什么
我看到有几种风格的网格。当记录很大时,人们建议使用 Angular UI Grid 而不是 Datatables。 我认为数据表正在按 1 填充每一行并导致性能问题。 是否无法修复类似于其他网格的数据
是否有人有在 Grid Engine/Sun Grid Engine/Son of Grid Engine 上运行 Docker 的经验,并且能够 monitor the resource used
我一直在阅读 CSS Grid tutorial在 CSS Tricks 中,但一个基本方面让我有点困惑。 似乎有两种方法可以决定一个网格元素跨越多少个单元格: grid-template-area使
调整 ag-Grid 的大小(更改浏览器窗口的大小)并在两个选项卡之间切换时收到以下警告: ag-Grid: tried to call sizeColumnsToFit() but the grid
我正在尝试在 python 2.7 中构建一个 5x5 网格的游戏板,表示为二维列表。我尝试将其写为 board = [["O"]*cols]*rows (cols 和 rows 已声明为 5)但是当
AgGrid 日期筛选器的格式是mm/dd/yyyy,但我想将其更改为yyyy/mm/dd 我该怎么做?日期过滤器是网格的 columnDefinition 的一部分,我在其中使用 filter: '
我有一个基本的 ag-grid 和一些简单的虚拟数据,但它只在我不导入库提供的 .css 文件时显示,即使这样它也显示不正确。 摘 self 的 package.json: "ag-grid": "1
我有一个标准的单元格编辑器,当我处于编辑模式时,单元格编辑器的宽度和高度不是单元格的完整宽度和高度。 我应该覆盖样式还是配置中有任何标志可以关闭此效果? 最佳答案 我有同样的问题。如果您查看 DOM,
概览 以前在 ag-grid 版本 <10.1.0 中,可以通过这种方式在不刷新网格的情况下添加一行: let model: IRowModel = this.gridOptions.api.getM
是否可以合并 wx.grid 中相邻的单元格?我的意思是水平作为一行中的单元格和垂直作为一列中的单元格。 最佳答案 有一种方法可以让文本跨越网格小部件中的多行或多列。 wxPython 演示中有一个名
关闭。这个问题需要更多 focused .它目前不接受答案。 想改进这个问题?更新问题,使其仅关注一个问题 editing this post . 6年前关闭。 Improve this questi
谷歌搜索了很多没有任何结果...按下回车键时网格的默认行为是向下移动光标。但我必须使单元格编辑器在当前单元格中打开。我可以轻松 Hook 关键事件,但如何打开编辑器? 最佳答案 import wx i
我是一名优秀的程序员,十分优秀!