Kaynağa Gözat

Fix [object Object] errors

Fixes #322
Fixes #330
Fixes #331
Fixes #334
tags/0.7.3
Michael Jackson 12 yıl önce
ebeveyn
işleme
411edae061
5 değiştirilmiş dosya ile 26 ekleme ve 5 silme
  1. +6
    -5
      mustache.js
  2. +1
    -0
      test/_files/zero_view.js
  3. +1
    -0
      test/_files/zero_view.mustache
  4. +1
    -0
      test/_files/zero_view.txt
  5. +17
    -0
      test/context-test.js

+ 6
- 5
mustache.js Dosyayı Görüntüle

@@ -121,7 +121,7 @@
};

function Context(view, parent) {
this.view = view || {};
this.view = view == null ? {} : view;
this.parent = parent;
this._cache = {};
}
@@ -135,9 +135,10 @@
};

Context.prototype.lookup = function (name) {
var value = this._cache[name];

if (!value) {
var value;
if (name in this._cache) {
value = this._cache[name];
} else {
if (name === '.') {
value = this.view;
} else {
@@ -148,7 +149,7 @@
value = context.view;

var names = name.split('.'), i = 0;
while (value && i < names.length) {
while (value != null && i < names.length) {
value = value[names[i++]];
}
} else {


+ 1
- 0
test/_files/zero_view.js Dosyayı Görüntüle

@@ -0,0 +1 @@
({ nums: [0, 1, 2] })

+ 1
- 0
test/_files/zero_view.mustache Dosyayı Görüntüle

@@ -0,0 +1 @@
{{#nums}}{{.}},{{/nums}}

+ 1
- 0
test/_files/zero_view.txt Dosyayı Görüntüle

@@ -0,0 +1 @@
0,1,2,

+ 17
- 0
test/context-test.js Dosyayı Görüntüle

@@ -43,6 +43,23 @@ describe('A new Mustache.Context', function () {
});
});

describe('A Mustache.Context', function () {
var context;

describe('with an empty string in the lookup chain', function () {
var view, context;
beforeEach(function () {
view = { a: '' };
view.a.b = 'value';
context = new Context(view);
});

it('is able to lookup a nested property', function () {
assert.equal(context.lookup('a.b'), view.a.b);
});
});
});

describe('Mustache.Context.make', function () {
it('returns the same object when given a Context', function () {
var context = new Context;


Yükleniyor…
İptal
Kaydet