2014-02-20 51 views
1

正如我想知道的問題所指出的那樣,javascript函數「$ find」只能工作,因爲它是由telerik控件提供的,或者它實際上是我可以使用的webforms事物。

我知道$ get是document.getElementById的一個快捷方式,但是我想知道$ web查找是由webforms提供的。如果是這樣,我會對如何將客戶端對象註冊到特定的控件ID非常感興趣。

我已經使用scriptControl.find(「id」)爲我自定義的目前爲止(其中scriptControl是由我提供)。但是,如果有更加標準的方式讓所有的客戶端對象都可以通過$ find來訪問,我更喜歡這樣做。

編輯: 通過MS代碼與螢火蟲的幫助下挖透露這樣的:

function Sys$_Application$findComponent(id, parent) { 
/// <summary locid="M:J#Sys.Application.findComponent" /> 
/// <param name="id" type="String"></param> 
/// <param name="parent" optional="true" mayBeNull="true"></param> 
/// <returns type="Sys.Component" mayBeNull="true"></returns> 
var e = Function._validateParams(arguments, [ 
    {name: "id", type: String}, 
    {name: "parent", mayBeNull: true, optional: true} 
]); 

if (e) throw e; 

return (parent ? 
((Sys.IContainer.isInstanceOfType(parent)) ? 
    parent.findComponent(id) : 
    parent[id] || null) : 
    Sys.Application._components[id] || null); 
} 

做這樣的事情

Sys.Application._components["id"] = {clientobject}; 

似乎是一個相當哈克的解決方案。

有什麼建議嗎?

回答

4

$get$find都不是Telerik特有的。它們包含在ASP.NET Ajax庫中。 $findSys.Application.findComponent(id, parent)reference)的快捷方式,因此只要此庫包含在頁面中,就可以隨意使用它。例如,而不是

scriptControl.find("id") 

你可以做

$find("id") 

注意$find只已註冊的組件中搜索,即那些添加到應用程序實例與Sys.Application.addComponent(component)方法。

+0

Will $ find(「id」,scriptControl)導致註冊scriptControl通過$ find找到?否則它可能有點誤導。目前我正在隱藏在scriptControl後面的閉包中創建並註冊我的客戶端對象。 scriptControl本身不是我想要註冊的客戶端對象 – Dbl

+0

@AndreasMüller,出於某種原因,我認爲'scriptControl'是您正在搜索的父控件。 '$ find'不會註冊任何東西,但是這裏的技巧是要認識到'$ find'只是在組件中搜索,即使用'addComponent'方法添加的元素 – Andrei

+0

是的。我只是在你的參考文獻中讀到這個。看到我不是從Component派生出來的,我想我將不得不按照我習慣的方式來調用它。注入Sys.Application._components可能會造成麻煩,否則。謝謝你的幫助! – Dbl

相關問題