我在MongoDB中有以下文档......
{
"_id" : ObjectId("531221cd960100960116b992"),
"username : "joe",
"address" : [
{
"zip" : "8000",
"city" : "Zurich"
},
{
"zip" : "6900",
"city" : "Lugano"
}
]
}
Run Code Online (Sandbox Code Playgroud)
...并检索第二个地址我使用以下语句:
db.users.find({ _id: ObjectId("531221cd960100960116b992") }, { addresses: { $slice: [0, 1] } } )
Run Code Online (Sandbox Code Playgroud)
这工作除了它还返回对象ID:
{ "addresses" : [ { "zip" : "6900", "city" : "Lugano" } ], "_id" : ObjectId("531221cd960100960116b992") }
Run Code Online (Sandbox Code Playgroud)
如何防止MongoDB返回对象ID?我知道我应该提供一个类似的投影_id : 0......但我应该把它放在上面的表达式中?我做了很多尝试......但没有成功.
谢谢.
我有一个服务,检查当前用户是否有权访问该路由.我希望将该服务作为解析的一部分进行调用,以便在用户不具有访问权限时从不加载视图.但是,在resolve函数中,$ state依赖项尚未包含路由器的实际状态.
.state('home', {
url: '/home',
templateUrl: 'app/home.html',
controller: 'HomeController',
controllerAs: 'main',
resolve: {
allowed: function(auth, $state) {
return auth.isAllowed($state.current.name);
}
},
})
Run Code Online (Sandbox Code Playgroud)
......但是$state.current.name在使用它时是空的.我怎样才能传递州名(即"家")?
我正在尝试使用ng-include和ng-init通过仅更改其数据来重用相同的组件.
组件代码("slider.html",没有控制器)如下所示:
<div ng-repeat="person in persons">
{{person.name}}
</div>
Run Code Online (Sandbox Code Playgroud)
从主视图,我想重用相同的组件更改"人员"列表,所以在视图中我有:
<!--slider #1 -->
<div ng-init="persons=english" ng-include ="'inc/app/views/widgets/slider.html'"></div>
<!-- slider #2 -->
<div ng-init="persons=german" ng-include ="'inc/app/views/widgets/slider.html'"></div>
Run Code Online (Sandbox Code Playgroud)
在控制器中我初始化2个列表"英语"和"德语",如下所示:
$scope.english = records.filter(function(t){return t.nationality=="english";});
$scope.german = records.filter(function(t){return t.nationality=="german";});
Run Code Online (Sandbox Code Playgroud)
会发生的是,2个组件显示相同的数据列表(德语); 有没有办法将2个不同的集合绑定到组件?
我正在使用chai-spies来确保控制器中的函数被调用,这是我的测试:
it('Should show right season and analysts when competition has been selected', function (done) {
scope.selectedCompetition = scope.competitions[3];
var spy = chai.spy(scope.selectedCompetitionChanged);
scope.selectedCompetitionChanged();
expect(spy).to.have.been.called();
done();
});
Run Code Online (Sandbox Code Playgroud)
scope.selectedCompetitionChanged函数在哪里。测试失败,并出现以下错误:
AssertionError: expected { Spy } to have been called
at Context.<anonymous> (base/tests/client/controllers/prediction.js?02f216981852d0775780926989e7266c6afb0af6:61:30)
Run Code Online (Sandbox Code Playgroud)
如果我显式调用该函数,怎么办?谢谢
我在引导程序模式中使用tinymce,但是页面滚动上的tinymce下拉菜单存在问题:基本上,它们的绝对位置不会更新,并且显示的位置错误。我准备了一个jsbin来显示问题:只需打开颜色选择器并滚动页面即可。
有什么提示吗?任何人都有相同的问题,并设法使其起作用?
谢谢
我正在尝试测试一个简单的减速器,其日期属性设置为今天。
const today = new Date();
export const initialState = {
today
};
console.log(new Date().toDateString()); // <--- real date
export default function globalReducer(state = initialState, action) {
console.log(new Date().toDateString()); // <--- mocked date
switch (action.type) {
default:
return state;
}
}
Run Code Online (Sandbox Code Playgroud)
通过我的基本测试
import globalReducer from "./reducer";
describe("Global reducer", () => {
beforeAll(() => {
jest.useFakeTimers("modern");
jest.setSystemTime(new Date("2021-02-18"));
});
afterAll(() => {
jest.useRealTimers();
});
it("should return the mocked date", () => {
expect(globalReducer(undefined, {}).today).toEqual(new Date('2021-02-18'));
});
});
Run Code Online (Sandbox Code Playgroud)
我注意到,模拟仅在减速器代码内起作用,但今天在其全局范围内总是返回真实日期而不是模拟日期。
setSystemTime如果我在测试设置文件中调用,则被today …
如何以反应形式验证密码确认?
const validate = values => {
const errors = {};
if (!values.username) {
errors.username = 'Required';
}
if (!values.password) {
errors.password = 'Required';
}
if (!values.confirmpassword ) {
errors.confirmpassword = 'Required' ;
}
return errors;
};
export default validate;
Run Code Online (Sandbox Code Playgroud)
这是我的验证页,我尝试过确认不匹配时进行密码验证...那是行不通的。有没有人愿意帮助我?
我想使用ng-disabled禁用div部分,但这确实可行。我也尝试使用fieldset代替div。禁用ng似乎无法正常工作。
下面是视图部分:
<div ng-disabled="model.disableDate">
<div>Date</div>
<div ion-datetime-picker ng-model="model.timeEntryDate" ng-change="onTimeEntryDateChange()" date="true" time="false" monday-first="true" am-pm="true">{{model.timeEntryDate|| "Select" | date: "dd/MM/yyyy"}} <i class="icon ion-ios-calendar-outline"></i> </div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是控制器部分:
if ($scope.model.pageState === condition) {
$scope.model.disableDate = true;
}
Run Code Online (Sandbox Code Playgroud)
即使在禁用条件下,此压光机也无法弹出。
angularjs ×4
reactjs ×2
unit-testing ×2
chai ×1
javascript ×1
jestjs ×1
mocking ×1
mongodb ×1
redux-form ×1
tinymce ×1
tinymce-4 ×1