我试图在一个视图中使用两个模型,并使用它们两个模板.我和Marionette一起工作.这是我初始化视图:
main_app_layout.header.show(new APP.Views.HeaderView({
model: oneModel,
model2 : twoModel}
));
Run Code Online (Sandbox Code Playgroud)
这是我的观点:
APP.Views.HeaderView = Backbone.Marionette.ItemView.extend({
template : '#view_template',
className: 'container',
initialize: function() {
//This correctly logs the second model
console.log(this.options.model2);
}
});
Run Code Online (Sandbox Code Playgroud)
这是模板:
<script id="view_template" type="text/template">
<p>{{twoModel_label}} {{oneModel_data}}</p>
<p>{{twoModel_label2}} {{oneModel_data2}}</p>
</script>
Run Code Online (Sandbox Code Playgroud)
它使用oneModel数据正确呈现所有内容,但不会呈现第二个,即使它正确记录它.我正在使用胡子作为我的模板语言.
有人可以帮忙吗?
我有几个问题以我想要的方式分解字符串.我有这样的网址:
http://SomeAddress.whatever:portWhatever/someDirectory/TARGETME/page.html
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用substring和indexOf而不是regex来获取字符串上的TARGETME部分.这是我现在正在使用的功能:
function lastPartofURL() {
// Finding Url of Last Page, to hide Error Login Information
var url = window.location;
var filename = url.substring(url.lastIndexOf('/')+1);
alert(filename);
}
Run Code Online (Sandbox Code Playgroud)
然而,当我写这篇文章时,我的目标是"page.html"部分,这就是它返回的内容,但是我无法重新配置它以完成我现在要做的事情.
如果可能的话,我希望它来自字符串的开头而不是结尾,因为在我尝试定位之前应该总是有一个url然后是一个目录,但我对这两种解决方案都很感兴趣.
这是一个类似的正则表达式,但它不安全(根据JSLint),因此我不介意用更实用的东西替换它.
/^.*\/.*\/TARGETME\/page.html.*/
Run Code Online (Sandbox Code Playgroud) 我想比较两个datepicker日期,看看它们是否超过7天.
我该怎么做?
我通常会看到他们的差异是否大于7,但这不会占数月等.
这是我的代码:
var datepickerBegin = $("#datepicker_start").val();
var datepickerEnd = $("#datepicker_to").val();
if (datepickerBegin - datepickerEnd > 7) {
alert('more than a week apart!')
}
Run Code Online (Sandbox Code Playgroud)
有小费吗??
我确信这是一个非常简单的解决方案,但到目前为止我发现的帖子似乎都没有直接解决这个问题:我如何循环收集以获得每个模型?
我试图使用的第一种方法是下划线的每种方法.这是我的电话和功能:
collection_var.each(paintThings);
Run Code Online (Sandbox Code Playgroud)
这是我的功能:
function paintThings() {
console.log(this);
console.log(this.model);
var thing_type = this.model.get("type"),
thing_other = this.model.get("otherAttribute");
console.log(this.model);
console.log(thing_type);
console.log(thing_other);
}
Run Code Online (Sandbox Code Playgroud)
现在,这是未定义的,并且this.model错误:
Uncaught TypeError: Cannot read property 'model' of undefined
Run Code Online (Sandbox Code Playgroud)
我知道答案很简单,但这让我发疯了!我是新来的强调.这里有人可以帮忙吗?如果它们更快/更好,我也会接受其他非下划线方法.
我也试过这个:
for (var i = 0, l = collection_var.length; i < l; i++) {
console.log(collection_var[i]);
}
Run Code Online (Sandbox Code Playgroud)
但那不是给我我想要的东西.
在CentOS(64位)系统上尝试运行phantomJS时,我遇到了一个奇怪的问题.
这是它报告的错误:
[4mRunning "qunit:all" (qunit) task[24m Testing http://localhost:8000/tests.html
Running PhantomJS...[31mERROR[39m
[31m>> [39m/home/jenkins/jenkins/workspace/nick_node_te/web-client/client/node_modules/grunt-contrib-qunit/node_modules/grunt-lib-phantomjs/node_modules/phantomjs/lib/phantom/bin/phantomjs: /home/jenkins/jenkins/workspace/nick_node_te/web-client/client/node_modules/grunt-contrib-qunit/node_modules/grunt-lib-phantomjs/node_modules/phantomjs/lib/phantom/bin/phantomjs: cannot execute binary file 0 [ '/home/jenkins/jenkins/workspace/nick_node_te/web-client/client/node_modules/grunt-contrib-qunit/node_modules/grunt-lib-phantomjs/node_modules/phantomjs/lib/phantom/bin/phantomjs: /home/jenkins/jenkins/workspace/nick_node_te/web-client/client/node_modules/grunt-contrib-qunit/node_modules/grunt-lib-phantomjs/node_modules/phantomjs/lib/phantom/bin/phantomjs: cannot execute binary file' ]
[33mWarning: PhantomJS exited unexpectedly with exit code 126. Use --force to continue.[39m
[31mAborted due to warnings.[39m
Run Code Online (Sandbox Code Playgroud)
我似乎无法找到关于此类崩溃的任何好文档.这通常和/或值得一个bug报告吗?
更新:
这些是我文件的权限:
-rwxr-x--x. 1 root root 11308856 Sep 26 12:39 phantomjs
Run Code Online (Sandbox Code Playgroud) 我是新来Require.js,我试图做一些事情,我以为会很简单,但也开始有疼痛感.
我正在尝试为我的Backbone应用程序定义一个全局命名空间,并将其作为模块加载.这是我的命名空间(main.js):
define(
['jquery',
'underscore',
'backbone',
'GlobalRouter'
],
function($, _, Backbone) {
var App= {
Models: {},
Views: {},
Collections: {},
Routers: {},
init: function() {
new App.Routers.GlobalRouter();
Backbone.history.start();
}
}
return App;
});
Run Code Online (Sandbox Code Playgroud)
这是我的config.js文件:
require.config({
// your configuration key/values here
baseUrl: "js", // generally the same directory as the script used in a data-main attribute for the top level script
paths: {
'jquery' : '//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min',
'underscore': 'vendor/underscore-min',
'backbone': 'vendor/backbone-min',
'marionette': 'vendor/backbone.marionette',
'main' : 'main'
}, // set up custom …Run Code Online (Sandbox Code Playgroud) 我最近从0.8~更新到最新版本的Node.js(1.10~),我在运行时收到一条消息:
util.pump() is deprecated. Use readableStream.pipe() instead.
Run Code Online (Sandbox Code Playgroud)
我试图将我的函数切换为readsStream.pipe(),但我认为它的工作原理并不相同.
所以我有三个问题:
这是我正在使用它的代码(带胡子)
var stream = mu.compileAndRender(template_file, json_object_from_db);
util.pump(stream, res);
Run Code Online (Sandbox Code Playgroud)
当我用readableStream.pipe替换util.pump时,我收到此错误:
ReferenceError: readableStream is not defined
Run Code Online (Sandbox Code Playgroud)
谁能帮助我指出正确的方向?
我正在处理一个简单的html type ="file"输入,我在Chrome中遇到了问题.具体来说,当您浏览并选择文件时,它会保存该值.但是,如果您重新浏览,则按取消它将清除该值.
html很简单:
<input type="file">
Run Code Online (Sandbox Code Playgroud)
这是一个简单的小提琴 - http://jsfiddle.net/78ghn/.
这种情况在其他浏览器中不会发生 - 是否有办法强制Chrome保留这些值?
我正在尝试将J SDoc合并到我的Grunt部署过程中.当我运行它时,我得到以下错误(预期):
>> JAVA_HOME is not set. Jsdoc requires Java to run.
Fatal error: Bad argument
Run Code Online (Sandbox Code Playgroud)
我知道JSDoc是基于java的,但我希望完全从等式中删除Java.有没有办法用现有的grunt插件或另一个只在Node中运行进程的插件?
我不想只为一个任务添加Java.这是傻瓜的差事吗?
dojo/parser在我的代码中使用时出现以下错误.
parser returned unfilled promise (probably waiting for module auto-load), unsupported by _WidgetsInTemplateMixin.
我有
define([
"dojo/_base/declare",
"dijit/_WidgetBase",
"myApp/base/_TemplatedMixin",
"dijit/_WidgetsInTemplateMixin",
"dojo/text!../templates/MyTemplate.html",
"dojo/i18n!../nls/Localized",
"myApp/js/utils/hint",
"dijit/form/ValidationTextBox",
"dijit/form/SimpleTextarea",
"dijit/form/Button",
"dojo/parser",
"dojo/domReady!"
], function (
declare,
_WidgetBase,
_TemplatedMixin,
_WidgetsInTemplateMixin,
template,
l10n,
hint
) {
'use strict';
/**
* @module
*/
return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
widgetsInTemplate: true,
/**
* @description Localized object for view
* @type {object}
*/
l10n: l10n,
/**
* @description Custom template for view
* @override
*/
templateString: template,
//postCreate: function …Run Code Online (Sandbox Code Playgroud) javascript ×9
backbone.js ×3
node.js ×3
gruntjs ×2
jquery ×2
marionette ×2
amd ×1
datepicker ×1
dijit.form ×1
dojo ×1
file-upload ×1
html ×1
indexof ×1
input ×1
jenkins ×1
jsdoc ×1
mustache ×1
npm ×1
phantomjs ×1
regex ×1
requirejs ×1
substring ×1