我正在使用jasmine来测试JavaScript代码.
我想以这种方式检查渲染功能的内容:
expect(this.view.el.innerHTML).toContain('<a href="#link">'+ 'regexp(any text)' +'</a>');
Run Code Online (Sandbox Code Playgroud)
可以将一些参数作为正则表达式传递吗?
如果有,怎么样?
我遇到以下情况.
当collection.length = 0
我想传递参数以便listTemplate
在listTemplate
(没有模型存在!)中显示消息.我怎样才能实现目标?
这是我的代码.
var ListView = Marionette.CompositeView.extend({
template: listTemplate,
// some code
});
Run Code Online (Sandbox Code Playgroud)
var itemView = Marionette.ItemView.extend({
// some code
});
Run Code Online (Sandbox Code Playgroud)
-
app.mainColumn.show(new ListView({
collection: tasks,
vent: myApp.vent
}));
Run Code Online (Sandbox Code Playgroud) 我有以下javascript代码
$(function(){
// loading source image
$('#panel').mousemove(function(e) { // binding mouse move event
// some code
});
$('#panel').mousedown(function(e) { // binding mousedown event
// some code
});
$('#panel').mouseup(function(e) { // binding mouseup event
// some code
});
});
function getResults() {
// some code
}
Run Code Online (Sandbox Code Playgroud)
以这种方式工作
<button onclick="getResults()">Crop</button>
<canvas id="panel" width="100" height="200"></canvas>
Run Code Online (Sandbox Code Playgroud)
我想重新编写这个js-plugin以使其更通用.
我认为使用它的好方法是以下方式:
$('#panel').myLib({
onSelect: getResults,
onClick: getResults
});
Run Code Online (Sandbox Code Playgroud)
任何想法我应该如何重写我的js代码来获得这个结果?谢谢
我需要使用一组函数扩展backbone.collection:
例:
var collection1 = Backbone.Collection.extend({});
var collection2 = Backbone.Collection.extend({});
Run Code Online (Sandbox Code Playgroud)
应该有以下自定义方法:
console.log(collection1.method1); // function () {}
console.log(collection1.method2); // function () {}
Run Code Online (Sandbox Code Playgroud)
另一方面
var collection3 = Backbone.Collection.extend({});
Run Code Online (Sandbox Code Playgroud)
不应该有这些方法.
console.log(collection3.method1); // undefined
Run Code Online (Sandbox Code Playgroud)
如何为collection1和collection2扩展Backbone.Collection而不为collection3扩展?
这是我的测试:
var test = function () {
$.each([1, 2], function () {
if(true !== false) { // it is just an example
alert('I am here');
return false; // how should I make the function test to stop or to exit here?
}
});
return true;
}?;
alert(test());
Run Code Online (Sandbox Code Playgroud)
我希望test
函数返回false但它返回true.
为什么?我该如何修复代码?请参阅评论以获取更多详细信息.
我正在尝试使用LESS旋转文本
简单地说,我尝试以下代码,但它不起作用.
.my-class {
color: #ff0000;
.rotate(90);
}
Run Code Online (Sandbox Code Playgroud)
这是我的jsfiddle http://jsfiddle.net/D2RLR/2750/
我正在使用jquery-handsontable来创建数据网格.
如果我做
$("#example1grid").handsontable('setDataAtCell', 0, 0,"test")
$("#example1grid").handsontable("setCellReadOnly", 0, 0);
Run Code Online (Sandbox Code Playgroud)
它会更改文本,但是当我单击时我可以编辑它.为什么?
这是测试http://jsfiddle.net/z9fYC/59/.
无论如何,如果我想让所有列号0都是只读的呢?
javascript ×5
jquery ×3
backbone.js ×2
css ×1
handsontable ×1
html ×1
jasmine ×1
less ×1
marionette ×1
plugins ×1