开始学习node.js和backbone.js,并使用TodoMVC示例作为我的向导.有几个部分我无法绕过头脑.见下文.
这是app.js.
var express = require('express')
, http = require('http')
, mongoose = require('mongoose')
, models = require('./models')
, routes = require('./routes')
, app = express();
app.configure(function () {
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(require('stylus').middleware({ src: __dirname + '/public' }));
app.use(express.static(__dirname + '/public'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
});
app.configure('development', function () {
app.use(express.errorHandler());
});
routes.init(app);
mongoose.connect("127.0.0.1", "todomvc", 27017);
http.createServer(app).listen(3000);
console.log("Express server listening on port 3000");
Run Code Online (Sandbox Code Playgroud)
Heres是./models:
var mongoose = require('mongoose'),
TodoSchema = new mongoose.Schema({
title: { 'type': …Run Code Online (Sandbox Code Playgroud) javascript model-view-controller node.js backbone.js todomvc
我为我正在研究的项目编写了一个jQuery的快速自定义扩展.我很难理解我希望实现的自定义onChange方法中'this'的范围.如果省略我的代码中间我调用webservice,但如果你检查最后两个方法,你会看到我的问题所在.我想用所选的值更改调用updateDetails方法.但是,当在onchange事件中调用该方法时,我显然会失去"this"的范围,因为this.materialListResponse在此上下文中返回为undefined.任何帮助我理解这一点的帮助将不胜感激.
$.fn.appendMaterials = function (options) {
this.options = options;
//Set Default Options
this.defaults = {
typeID: '66E1320D-51F9-4900-BE84-6D5B571F9B80'
};
this.options = $.extend({}, this.defaults, options);
//
Code here to call web service and generate response XML
//
this.materialListResponse = $.xml2json(
$.parseXML($(this.materialListWebservice()).find("GetMaterialTreeResponse").text())).Materials.Material;
this.appendOptionString = function () {
var i = 0;
this.optionString = '<option>'
for (i = 0; i < this.materialListResponse.length; i++) {
this.optionString += '<option>' + this.materialListResponse[i].MaterialCode + '</option>';
};
this.append(this.optionString);
return this;
};
this.appendOptionString();
this.updateDetails = function () {
for (i …Run Code Online (Sandbox Code Playgroud)