我使用nodejs/express/mongoose/angularjs.我想更新一个名为Lists的集合,它有几个属性,其中一个是项目数组.在下面的代码中,我在items数组中推送一个新的任务项.一切正常,但更新功能不会发回更新的集合,然后我必须对数据库执行另一个查询.有没有更有效的方法来做到这一点?
nodejs/express代码:
exports.addTaskToList = function(req, res) {
var listId = req.params.Id;
var taskId = req.params.TaskId;
Lists.update({_id: listId}, {$push: {items: taskId}}, {safe:true, upsert: true}, function(err, result){
if(err) {
console.log('Error updating todo list. ' + err);
}
else{
console.log(result + ' todo list entry updated - New task added');
Lists.findById(listId).populate('items').exec(function (err, updatedEntry) {
if (err) {
console.log('Unable to retrieve todo list entry.');
}
res.send(JSON.stringify(updatedEntry));
});
}
});
};
Run Code Online (Sandbox Code Playgroud)
此外,数组项是ObjectIds的数组.这些项目位于单独的模式中,因此位于单独的集合中.是否可以推送整个对象,而不仅仅是其_id,以便不会创建另一个集合?
我正在使用Angular UI来呈现手风琴中的小数据库条目.在第一次试验中,我使用了bootstrap,但是当我整合AngularJS视图时,手风琴不再完全正常工作(空的href ......).然后我用角度UI bootstrap one和默认模板替换了我的bootstrap手风琴.
我的问题是,在bootstrap版本中,我设法根据手风琴标题(我使用ng-repeat指令和标题内的ng-style)对标题进行了风格化.我尝试使用Angular UI做同样的事情,但即使我的自定义类也没有渲染.
这个示例代码在bootstrap上运行得很好,但ui.boostrap手风琴不再适用:
accordion-group.accordion-groupLog(ng-repeat="item in data.entries | filter:search")
accordion-heading.accordion-headingLog(ng-style="{backgroundColor: styles[item.importance-1].bkcolor, color: styles[item.importance-1].color}")
{{item.title}} ({{item.importance}})
Run Code Online (Sandbox Code Playgroud)
这里的目标是基于项目字段应用不同的样式(背景颜色和文本颜色).此外,手风琴 - headingLog类是为了调整手风琴的默认大小.
这是渲染的代码:
<div class="accordion-groupLog accordion-group ng-scope" ng-repeat="item in data.entries | filter:search">
<div class="accordion-heading">
<a class="accordion-toggle ng-binding" ng-click="isOpen = !isOpen" accordion-transclude="heading">
......
Run Code Online (Sandbox Code Playgroud)
我期待的是:
<div class="accordion-groupLog accordion-group ng-scope" ng-repeat="item in data.entries | filter:search">
<div ng-style="{backgroundColor: styles[item.importance-1].bkcolor}" class="accordion-heading accordion-headingLog" style="background-color: rgb(214, 24, 40);">
Run Code Online (Sandbox Code Playgroud)
[编辑]我试图将accordion-headingLog类放入ng-class属性,但它也不起作用.为了测试,我尝试将类和风格应用于手风琴的主体内部,并且效果很好.我认为accordionHeading指令不接受任何类或属性?如何在标题上动态应用样式然后???
[编辑]另一个试验是建立我自己的模板.我能够将accordion-headingLog类应用于标题,但是如何设置可自定义的样式?我尝试使用ng-style并应用固定样式,但它不起作用.
script(type="text/ng-template", id="template/accordion/accordion-group.html").
div.accordion-group
div.accordion-heading.accordion-headingLog(ng-style="{background-color: #123456")
a.accordion-toggle(ng-click="isOpen = !isOpen", accordion-transclude="heading") {{heading}}
div.accordion-body(collapse="!isOpen")
div.accordion-inner(ng-transclude)
Run Code Online (Sandbox Code Playgroud) 我最近想尝试VS2013和SC的Git工具.一切都很好,直到我做了什么,但不知道是什么...我创建了一个nodejs应用程序并将其推送到github.但是,"main"脚本没有直接进入root repo目录,因此我手动创建了另一个repo,以便能够将其推送到heroku.好吧,之后,另一个分支出现在团队资源管理器中,我的主分支被告知所有文件都处于挂起删除状态.我同步了repo并且很好地推入了github但是我必须手动执行它因为我在VS中出错了.现在repo被推送了,我在Sync时不再有任何错误,但是每个文件仍然有那些待处理的删除状态.
此外,因此,我无法对文件进行任何更改并使用VS推送它,我必须手动推送.
任何的想法 ?(我知道这个问题真的不清楚,但我会尽我所能;))
我曾经以这种方式连接到我的AWS-RDS实例
import MySQLdb
db = MySQLdb.connect(host=os.getenv('RDS_ENDPOINT'),
user=os.getenv('RDS_USER'),
passwd=os.getenv('RDS_PWD'),
db=os.getenv('RDS_DB'))
Run Code Online (Sandbox Code Playgroud)
或借助sqlalchemy,但今天它似乎拒绝处理该错误 (2006, 'SSL connection error: SSL_CTX_set_tmp_dh failed')
我尝试更新所有python软件包(mysqlclient,sqlalchemy),重新安装mysqlclient-dev,手动重新安装,OpenSSL v1.1.1a但仍然存在相同的错误。
[编辑]
我设法使用MySQL CLI连接到相同的数据库
mysql --user=$RDS_USER --host=$RDS_ENDPOINT --password=$RDS_PWD $RDS_DB
Run Code Online (Sandbox Code Playgroud)
[解]
看来这是驱动程序问题。我尝试使用mysqlclientpython 3并收到此错误。接下来,我尝试按要求使用mysql.connector,但遇到了编码问题(如sqlalchemy文档中所述)。最后,我以pymysql似乎可以与sqlalchemy 一起使用的驱动程序结束。
我的 Angular 应用程序有问题。应用程序第一次运行良好,可以在内部导航,但是当我尝试使用 F5 刷新页面时失败。当按下 F5 键时,partial 被调用到服务器,服务器显然响应的是局部视图,而不是整个应用程序。
节点路由:
app.get('/', node_routes.welcome);
...
app.get('/profile', pass.ensureAuthenticated, profile_routes.profile);
app.get('/profile/:name', pass.ensureAuthenticated, profile_routes.partials);
app.post('/profile/update', pass.ensureAuthenticated, profile_routes.update);
...
Run Code Online (Sandbox Code Playgroud)
控制器:
exports.profile = function(req, res) {
var user = req.user;
Profile.findOne({ username: user.username }, function(err, profile) {
if (err) {
res.redirect('/');
}
res.render("profile");
});
};
exports.partials = function(req, res) {
var name = req.params.name;
var user = req.user;
Profile.findOne({ username: user.username }, function(err, profile) {
if (err) {
res.redirect('/');
}
res.render(path.join(__dirname + '/../views/profile/' + name));
});
};
exports.update …Run Code Online (Sandbox Code Playgroud) 我有一个简单的控件,其中包含一个 DataGrid,其中 ItemsSource 绑定到 DataTable。当我填充 DataTable 时,我可以看到 DataGrid 中添加了行,但没有显示任何数据。我没有为此 DataGrid 使用任何特殊样式(采用默认样式),唯一的设置是将 AutoGenerateColumn 设置为 True。
在 XAML 中
<DataGrid AutoGenerateColumns="True" ItemsSource="{Binding TableResult}"/>
Run Code Online (Sandbox Code Playgroud)
在视图模型中
private DataTable tableResult = new DataTable();
public DataTable TableResult
{
get { return tableResult; }
set { tableResult = value; OnPropertyChanged("TableResult"); }
}
private void FillTable()
{
DataColumn c = new DataColumn();
c.ColumnName = "Col1";
this.TableResult.Columns.Add(c);
c = new DataColumn();
c.ColumnName = "Col2";
this.TableResult.Columns.Add(c);
DataRow row1 = this.TableResult.NewRow();
row1["Col1"] = "Blue";
row1["Col2"] = "12";;
this.TableResult.Rows.Add(row1);
DataRow row2 = …Run Code Online (Sandbox Code Playgroud) 我的python脚本有问题
首先,我将环境变量定义为
export TEST=test
Run Code Online (Sandbox Code Playgroud)
我的Python脚本非常简单“ test.py”
import os
print os.environ['TEST']
Run Code Online (Sandbox Code Playgroud)
所以当我用
~ $ python test.py
Run Code Online (Sandbox Code Playgroud)
我已经test打印出了预期的结果。但是,如果我使用
~ $ sudo python test.py
Run Code Online (Sandbox Code Playgroud)
我有一个KeyError: 'TEST'错误。
我错过了什么?
我有一个numpy矩阵,我想将它转换为pandas数据帧/系列.一个例子:
m = np.array([[1, 2], [11, 22]])
Run Code Online (Sandbox Code Playgroud)
这将导致
a
0 [1, 2]
1 [11, 22]
Run Code Online (Sandbox Code Playgroud) 我已经阅读了很多关于这个主题的帖子,发现几乎总是相同的解决方案,但它对我不起作用......
我的问题如下:我想使用Twitter Bootstrap 2.3.2及其导航栏,所以我包含了css和js文件.就在此之前,我还包括jquery.然后,我在bootstrap网站上给出了一个非常好的例子.但是,我现在想要将菜单项设置为活动状态,并从所有其他项中删除活动类.我在bootstrap.js文件中看到此函数是内置的,因此不再包含脚本代码.问题是菜单项永远不会切换为活动状态.然后我尝试添加一个jquery脚本来强制删除所有活动类,并将活动类添加到单击的一个项目中.没啥事儿.
所以,请帮助!! 我在jsfiddle中尝试了相同的代码,它运行正常,问题来自于玉?从快递布局?怎么解决?
这是我使用的代码:
server.js
var express = require('express');
var app = express();
var port = 3000;
app.set('view engine', 'jade');
app.set('view options', {layout: true});
app.set('views', __dirname + '/views');
app.configure(function () {
this.use(express.cookieParser());
this.use(express.session({ secret: 'shhhhhhhhh' }));
this.use(express.static(__dirname + '/public'));
this.use(app.router);
});
app.get('/', function (req, res) {
res.render('index')
});
});
app.get('/about', function (req, res) {
res.render('about')
});
});
app.listen(port, function () {
console.log('listening in http://localhost:' + port);
});
Run Code Online (Sandbox Code Playgroud)
/views/layout.jade
!!! 5
html
head
title Test Application
link(type='text/css', rel='stylesheet', …Run Code Online (Sandbox Code Playgroud) 我有一个包含数据网格的应用程序。在此数据网格中,存在类型为DataGridComboboxColumn的列。诀窍是,我在资源字典中定义了一个针对Combobox的样式,但是它似乎不适用于编辑模式下的DataGridComboboxColumn,但它适用于“常规” Combobox。
我无法重复该资源,因为DataGridComboboxColumn不能用作目标类型。
任何的想法 ?
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style x:Key="StandardComboBox" TargetType="ComboBox">
<Setter Property="Foreground" Value="{StaticResource Foreground}"/>
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
<Setter Property="MinWidth" Value="120"/>
<Setter Property="MinHeight" Value="20"/>
<Setter Property="Template">
...
</Setter>
<Style.Resources>
<Style TargetType="ComboBoxItem">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Template">
...
</Setter>
</Style>
</Style.Resources>
</Style>
</ResourceDictionary>
<Window x:Class="OtdrQualifTools.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<DataGrid AutoGenerateColumns="False" Height="200" HorizontalAlignment="Stretch" ItemsSource="{Binding AcquisitionList}"
Margin="0,200,0,0" Name="dataGridAcquisitions" VerticalAlignment="Top" >
<DataGrid.Columns>
<DataGridComboBoxColumn Header="Mode" Width="SizeToHeader" …Run Code Online (Sandbox Code Playgroud) 我有一个泛型问题.我是那些课:
abstract class BaseTestClass<T> : where T : class, new()
{
//base test class implementation
public abstract void Run(BaseDataClass<T> data);
}
class BaseDataClass<T> : where T : class, new()
{
//base data class implementation
}
class DataA : BaseDataClass<SettingsA>
{
//some stuff
}
class TestA : BaseTestClass<SettingsA>
{
//Works!
public override void Run(BaseDataClass<SettingsA> data)
{
}
//Doesn't Work!
public override void Run(DataA data)
{
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,为什么我不能在抽象方法中使用继承的类?
[编辑]编译时的错误是:
TestA没有实现继承的抽象成员Run(BaseDataClass)
我有衍生类的问题.
我有一个父类和几个子类
public abstract class Parent
{}
public class Child1 : Parent
{}
public class Child2 : Parent
{}
public class Child3 : Parent
{}
Run Code Online (Sandbox Code Playgroud)
然后我有一个这些对象的列表
List<Parent> myList = new List<Parent>(){ new Child1(), new Child2(), new Child2() .....};
Run Code Online (Sandbox Code Playgroud)
我想要一个函数来检索此列表的对象,指定其类型.现在,我为每种子类型构建了一个这样的方法,但是当子类型数量增加时,可能会出现问题
public Child1 GetChild1()
{
Child1 child = myList.FirstOrDefault(ch => ch is Child1) as Child1;
if(child == null)
{
child = new Child1;
myList.Add(child);
}
return child;
}
Run Code Online (Sandbox Code Playgroud)
我正在寻找类似的东西
public Parent GetChild(Type typeOfChild)
-- or --
public Parent GetChild(string typeOfChild)
-- or …Run Code Online (Sandbox Code Playgroud)