2012-11-20 25 views
0

您好我正在嘗試將此代碼從主幹轉移到基礎結構。我猜測它更多的是一個jQuery問題作爲骨幹使用$ el作爲幫手嗎?

骨幹代碼

//this.el is the root element of Backbone.View. By default, it is a div.  
//$el is cached jQuery object for the view's element. 
//append the compiled template into view div container 

    this.$el.append(***some html***); 

這樣的console.log(這一點。$ EL)返回一個對象

我曾嘗試

console.log($(** some html **)) 

但這只是返回的名稱第一次潛水,而不是對象...

回答

0

var el在javascript中通常指s到你試圖獲取/設置的元素。

例如,在jQuery的一些常見的是:

$('this')

或在Javascript則可能是:

getElementById('your element e.g: my-awesome-id')

對於這種情況,我認爲它實際上會被讀爲:

this.('div').append('<span>we append something here</span>')

,而不是console.log($(** some html **))嘗試使用console.log(this.$el)

我希望這有助於你對你的方式,乾杯!