我有三个非常简单的角度js应用程序的文件
的index.html
<!DOCTYPE html>
<html ng-app="gemStore">
<head>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js'></script>
<script type="text/javascript" src="app.js"></script>
</head>
<body ng-controller="StoreController as store">
<div class="list-group-item" ng-repeat="product in store.products">
<h3>{{product.name}} <em class="pull-right">{{product.price | currency}}</em></h3>
</div>
<product-color></product-color>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
产品color.html
<div class="list-group-item">
<h3>Hello <em class="pull-right">Brother</em></h3>
</div>
Run Code Online (Sandbox Code Playgroud)
app.js
(function() {
var app = angular.module('gemStore', []);
app.controller('StoreController', function($http){
this.products = gem;
}
);
app.directive('productColor', function() {
return {
restrict: 'E', //Element Directive
templateUrl: 'product-color.html'
};
}
);
var gem = [
{
name: "Shirt",
price: 23.11,
color: "Blue"
},
{ …Run Code Online (Sandbox Code Playgroud) 这是我在Postgres中遇到的一个奇怪的,不需要的行为:当我使用复合主键创建Postgres表时,它会对复合组合的每一列强制执行NOT NULL约束.
例如,
CREATE TABLE distributors (m_id integer, x_id integer, PRIMARY KEY(m_id, x_id));
Run Code Online (Sandbox Code Playgroud)
强制NOT NULL列上的约束m_id和x_id,我不想!MySQL没有这样做.我认为Oracle也不会这样做.
据我所知,PRIMARY KEY强制执行UNIQUE并NOT NULL自动执行但对单列主键有意义.在多列主键表中,唯一性由组合确定.
有没有简单的方法来避免Postgres的这种行为?
如果我执行这个:
CREATE TABLE distributors (m_id integer, x_id integer);
Run Code Online (Sandbox Code Playgroud)
我NOT NULL当然没有任何限制.
我使用group_concat将很多行连接成一个.
我使用以下方法将group concat设置为10000:
SET group_concat_max_len = 10000;
Run Code Online (Sandbox Code Playgroud)
但即便如此,我的输出单元仍然不完整,最终以...结束
我尝试设置group_concat_max_len = 20000甚至没有帮助.
我也尝试将group_concat_max_len设置为99999999.它仍然无法完成输出文本.我检查了长度= 230个字符的组连续停止之一然后给...
还有其他方法吗?
我有一个列表可以说:
dataSet$mixed_bag <- list("Hello", c("USA", "Red", "100"), c("India", "Blue", "76"))
Run Code Online (Sandbox Code Playgroud)
我想迭代这个列表并根据列表的内容创建新的变量.伪代码看起来像这样.
foreach row in dataSet$mixed_bag {
if (sapply(dataSet$mixed_bag, length) == 3) {
dataSet$country <- dataSet$mixed_bag[[row]][1];
dataSet$color <- dataSet$mixed_bag[[row]][2];
dataSet$score <- dataSet$mixed_bag[[row]][3];
} else if (sapply(dataSet$mixed_bag, length) == 2) {
#Do something else
} else {
# Do nothing
}
}
Run Code Online (Sandbox Code Playgroud)
请建议我如何在R中执行此操作
我在R中使用grepl()来搜索我的文本中是否存在以下任一类型.我现在这样做:
grepl("Action", my_text) |
grepl("Adventure", my_text) |
grepl("Animation", my_text) |
grepl("Biography", my_text) |
grepl("Comedy", my_text) |
grepl("Crime", my_text) |
grepl("Documentary", my_text) |
grepl("Drama", my_text) |
grepl("Family", my_text) |
grepl("Fantasy", my_text) |
grepl("Film-Noir", my_text) |
grepl("History", my_text) |
grepl("Horror", my_text) |
grepl("Music", my_text) |
grepl("Musical", my_text) |
grepl("Mystery", my_text) |
grepl("Romance", my_text) |
grepl("Sci-Fi", my_text) |
grepl("Sport", my_text) |
grepl("Thriller", my_text) |
grepl("War", my_text) |
grepl("Western", my_text)
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来编写这段代码?我可以将所有类型放在一个数组中,然后以某种方式使用grepl()它吗?
我的Ruby on Rails控制器中有一个Global JSON变量.它看起来像@rails_side_json = {:name =>'Will',:age => 23} .to_json
我希望将其分配给我的javascript变量(var javascript_side_json),该变量位于名为custom.js.erb的javascript文件中
赋值完成后javascript_side_json变量中的值应该等同于我编写var javascript_side_json = {"name":"Will","age":23};
我无法通过编写var javascript_side_json = <%= @rails_side_json%>来实现这一点
我怎样才能做到这一点?我是否需要在多个文件中进行更改?
在我的前端JavaScript应用程序中,我发出了一个从服务器获取数据的ajax请求.一旦我获得数据,我想将该信息返回给视图.
var view_data;
$.ajax({
url:"/getDataFromServer.json",
//async: false,
type: "POST",
dataType: "json",
success:function(response_data_json) {
view_data = response_data_json.view_data;
console.log(view_data); //Shows the correct piece of information
return view_data; // Does not work. Returns empty data
}
});
// return view_data; --> Keeping the return outside of the ajax call works but then I need to make my ajax call synchronous in order for this return clause to be executed after the ajax call fetches data.
Run Code Online (Sandbox Code Playgroud)
我该怎么做?
我的一个python脚本在Postgres数据库上运行了一些ALTER TABLE查询.发生了一些错误,桌子被锁定了.当我在任何这些表上运行任何查询时,它会告诉我Query Query并没有任何反应.目前,我只能通过关闭我的系统并重新启动它来删除此锁.请告诉我一个更好的方法.这是一个Windows主机.
当我第一次访问许多新网站时,我看到:
我找不到哪两段代码可以区分这两种情况.对于我的网站,我被#2困住了.我正在尝试实现#1,用户只需重新使用在其他网站上输入的电子邮件即可.
我使用了这样的代码:
<input type="email" name="email" id="frmEmailA" placeholder="name@example.com" required autocomplete="email">
Run Code Online (Sandbox Code Playgroud) 我使用的是Python 2.7和MySQLdb 1.2.3.我尝试了在stackoverflow和其他论坛上找到的所有内容来处理我的脚本抛出的编码错误.我的脚本从源MySQL DB中的所有表读取数据,将它们写入python StringIO.StringIO对象,然后将该数据从StringIO对象加载到Postgres数据库(显然是UTF-8编码格式.我通过查看属性找到了这个 -使用psycopg2库的copy_from命令在pgadmin中定义数据库.
我发现我的源MySQL数据库在latin1_swedish_ci编码中有一些表,而其他表用utf_8编码格式(在information_schema.tables中找到这个来自TABLE_COLLATION).
我根据我在互联网上的研究,在Python脚本的顶部编写了所有这些代码.
db_conn = MySQLdb.connect(host=host,user=user,passwd=passwd,db=db, charset="utf8", init_command='SET NAMES UTF8' ,use_unicode=True)
db_conn.set_character_set('utf8')
db_conn_cursor = db_conn.cursor()
db_conn_cursor.execute('SET NAMES utf8;')
db_conn_cursor.execute('SET CHARACTER SET utf8;')
db_conn_cursor.execute('SET character_set_connection=utf8;')
Run Code Online (Sandbox Code Playgroud)
我仍然得到了UnicodeEncodeError下面这一行:cell = str(cell).replace("\r", " ").replace("\n", " ").replace("\t", '').replace("\"", "") #Remove unwanted characters from column value,
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 47: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud)
在写入StringIO对象时,我编写了以下代码行来清理源MySQL数据库的每个表中的单元格.
cell = str(cell).replace("\r", " ").replace("\n", " ").replace("\t", '').replace("\"", "") #Remove unwanted characters from column …Run Code Online (Sandbox Code Playgroud) javascript ×4
postgresql ×3
html ×2
mysql ×2
r ×2
ajax ×1
angularjs ×1
email ×1
encoding ×1
erb ×1
grepl ×1
group-concat ×1
jquery ×1
json ×1
loops ×1
null ×1
primary-key ×1
python ×1
regex ×1
unique ×1