我正在为 Backbone.Collection 编写规范。
\n我想使用 jasmine 在单元测试 javascript 中检查以下语句:
should the models be ordered by starting with the most recent.\n
Run Code Online (Sandbox Code Playgroud)\n\n模型中要检查的关键值是id
(它是一个整数)。
例如,如果集合如下所示,则该集合已排序:
\n\n[\n{id: 5, \xe2\x80\xa6.}, // the most recent\n{id: 2, ...},\n{id: 1, ...}\n]\n
Run Code Online (Sandbox Code Playgroud)\n\n我的问题是:
\n1) 有没有一种茉莉花方法可以进行这种检查?
\n2)如果没有,用 javascript 制作它的最佳方法是什么?也许使用一些像下划线这样的库。
我有两个Backbone视图,MainView
和PopupView
.
MainView包含一个帮助按钮.当触发帮助按钮处理程序时,它会显示Backbone.View.
我的问题是如何从MainView
模块中测试这种行为?
这是我的代码MainView
:
var MainView = Backbone.View.extend({
events: {
'click #help' : 'showPopUp'
},
showPopUp: function() {
var popupView = new PopupView();
app.vent.trigger('showModal', popupView);
}
});
Run Code Online (Sandbox Code Playgroud)
这是关于mainView.spec的代码:
describe("When help button handler fired", function() {
beforeEach(function() {
this.view.render();
this.view.$el.find('#help').trigger('click');
});
it("shows the popup", function() {
// what should I do?
});
});
Run Code Online (Sandbox Code Playgroud)
这是关于应用程序的代码:
var app = new Marionette.Application();
app.addRegions({
header: '#header',
sidebar: '#sidebar',
main: '#main',
modal: '#modal'
});
app.vent.on('showModal', function(view) {
var …
Run Code Online (Sandbox Code Playgroud) 我需要通过CSS实现以下任务:
我有一个固定宽度的div.
在这个div我需要以下面的方式显示名字,第二名和最终其他名字.
例1
---------------
First-Name
Secondo-Name
---------------
Run Code Online (Sandbox Code Playgroud)
examaple 2
---------------
Very-Long-First
-Name
Second-Name
---------------
Run Code Online (Sandbox Code Playgroud)
如果我尝试使用word-break: break-all;
它将适用于example 2
但不适用于example 1
:
例1
---------------
First-Name Seco
nd-Name
---------------
Run Code Online (Sandbox Code Playgroud)
使用CSS解决此问题的最佳方法是什么?
如果不可能,使用javascript修复它的最佳方法是什么?
我PagodaBox
用来扩展PHP
通过部署的应用程序git
.
在这个应用程序中,我想也包括在内Node.js
.
对我来说,PagodaBox似乎无法集成Node.js. 你能推荐我一个IaaS
,PaaS
还是SaaS
服务?
运行以下Jasmine测试(1),测试成功执行但我面临主测试页面的递归加载.
这是我的测试(1),这里是我运行测试的模块(2):
有任何想法吗?我该如何解决这个问题?
PS:
问题只涉及Chrome和Safari浏览器.
这是一个例子:jsfiddle.net/shioyama/EXvZY
(1)
describe('When Submit button handler fired', function () {
beforeEach(function () {
spyOn(MyView.prototype, 'submitForm');
this.view = new MyView();
this.view.render();
this.view.$el.find('form').submit();
});
it('submitForm should be called', function () {
expect(MyView.prototype.submitForm).toHaveBeenCalled();
});
});
Run Code Online (Sandbox Code Playgroud)
(2)
var MyView = Backbone.View.extend({
events: {
'submit form' : 'submitForm'
},
submitForm: function (event) {
event.preventDefault();
// some code
}
});
Run Code Online (Sandbox Code Playgroud) 以下两种实现ajaxRequest(1)(2)的方法应该是等效的.
话说回来:
stub jQuery.ajax
使用sinon和代码(2)我得到一个错误.我该如何解决? 请参阅代码(3)中的注释以获取更多详细信息.
(1)
ajaxRequest: function (message, callback) {
return $.ajax({
url: backendRouter.generate('feedback_send'),
type: 'POST',
dataType: 'json',
data: {
message: message
},
success: callback
});
}
Run Code Online (Sandbox Code Playgroud)
(2)
ajaxRequest: function (message, callback) {
return $.ajax({
url: backendRouter.generate('feedback_send'),
type: 'POST',
dataType: 'json',
data: {
message: message
}
}).success(callback);
}
Run Code Online (Sandbox Code Playgroud)
(3)
it("should execute the callback function on success", function () {
spyOn($, "ajax").andCallFake(function(options) {
options.success();
}); // If I use the code (2) I get the following …
Run Code Online (Sandbox Code Playgroud) 我正在阅读有关npm开发人员指南的文档.
我想知道是否可以使用npm使用javascript/css/html编写Web客户端应用程序?
如果是的话,github上有一些例子吗?
例如,我的客户端Web应用程序依赖于requirejs, jquery, underscore and backbone
.
我可以使用npm
自动下载供应商目录中的最新版本requirejs, jquery, underscore and backbone
吗?
如果没有,是否有其他工具/方法来实现这一目标?
我有一个Marionette.CompositeView
需要渲染集合.
我想过滤这个集合fetch
和add
动作.
我尝试使用以下代码(1)但我收到以下错误(2).
任何想法,谢谢.
(1)
var myCompositeView = Marionette.CompositeView.extend({
initialize: function () {
this.collection = app.taskCollection.where({type: 'todo'});
}
});
Run Code Online (Sandbox Code Playgroud)
(2)
// Uncaught TypeError: Object has no method 'on'
Run Code Online (Sandbox Code Playgroud) 通过使用bootstrap我想显示绿色和红色标签,其上下文类似于av或x.
v应为绿色,x应为红色.
我写了下面的代码,但我希望有更好的效果.
<span class="badge badge-success">V</span>
<span class="badge badge-important">X</span>
Run Code Online (Sandbox Code Playgroud)
任何想法我应该如何通过使用bootstrap得到它?
以下是使用引导标签和徽章获得的示例.
如果我在谷歌Chrome控制台中运行以下代码,我会得到以下结果
var x = 1;
alert(delete x); // false
Run Code Online (Sandbox Code Playgroud)
eval('var y = 2');
alert(delete y); // true
Run Code Online (Sandbox Code Playgroud)
为什么在第一个例子中没有删除变量,在第二个例子中它被删除了?
javascript ×8
backbone.js ×4
jasmine ×4
css ×2
marionette ×2
node.js ×2
cloud ×1
css3 ×1
jquery ×1
npm ×1
paas ×1
php ×1
saas ×1