3

i am trying to output some dafault values of a backbone Model via creating a View but the node is showing the error "Property '$' of object # is not a function at _.extend._ensureElement". I can show default values from model directly as i am doing in the code below but not by using view. To show an example i've commented out the //myView = new firstView(); so you can see the output but soon i remove the comments i get the error. Please let me know what is missing and something i am doing wrong. Already tried wrapping the code within $(function(){}) but no luck.

     express = require('express');
     $ = require('jQuery');
     _ = require('underscore');
     Backbone = require('Backbone');
     app = express();

     app.use(express.static(__dirname + ''));
     app.use(express.bodyParser());
     app.listen(process.env.PORT || 3000);

     Person = Backbone.Model.extend({
        defaults: {
            'name': 'Joe Blog',
            'job': 'Web Developer'
        }
     });

     firstPerson = new Person();
     firstView = Backbone.View.extend({

        initialize: function() {
            this.render();
        },
        render: function() {
            console.log(firstPerson.get('job'));
            return this;

        }
     })

     //myView = new firstView();
     console.log(firstPerson.get('name'));

C# Calculator Text Input Validation

I am currently writing a calculator application. One part of this application is a Simple Calculator that works like the calculator in windows (using windows 8). It can parse the numbers entered in the textbox. However, if the user does not enter in the correct form such as 5 * * 5 it will give an error. I want it to check the character entered before to see if its an operator and if it is, replace it such as 5 * / 5 to become 5 / 5 as the user is typing. Also it will need to check the parenthesis are in the correct order such as () or () not )(. The other thing it will need to check is that the number being entered only has one decimal point. For example, 4.38585 + 5.32948. I have already limited key entries to only numbers and operators. I have checked this for some time now, but have not seen any solutions.

4

1 回答 1

7

Backbone 代理 jQuery 库。它通常通过搜索全局$变量来实现。由于您在节点环境中执行代码,因此您需要手动执行此操作:

var Backbone = require('backbone'),
    $ = require('jQuery');

Backbone.$ = $;

作为旁注,您确实应该var在变量前面使用关键字,以使变量成为函数范围的局部变量。(见这个问题

于 2013-07-21T16:46:25.743 回答