0

저는 Knockout과 그 템플릿 기능에 익숙하지 않습니다. 다음 html을 가졌습니다. 누군가가 적절한 템플릿을 사용하여 문자열 리터럴과 데이터 소스를 대체 할 수있게 도와주었습니다. 편집, #은knockout js 템플릿 json 데이터 소스를 템플릿에 전달합니다.

<tr data-bind="foreach: fundClasses"> 
    <td class="span1"> 
     <span data-bind="visible: $index() == 0"> Rate Index</span> 
    </td> 
    <td class="span1 protected"> 
     <span data-bind=" editable:INDEX_ID, editableOptions: {name:'INDEX_ID',mode: 'popup',type: 'select', source: rateIndex,pk: ID, url: '/create/EditInPlace'}"></span> 
    </td> 
</tr> 

나는 위의 조각에 rateIndex, INDEX_ID을 대체하고자, 여기에 대한 도움을 크게 감사합니다.

감사 조지

답변

0

내가 그래서 그 비슷한 문제를 찾고 다른 사람을 돕는 것 때문에 응답 생각, 자신을 알아 냈

템플릿 :

<script id="textBoxTemplate" type=“text/html”> 
    <!-- ko foreach: $data --> 
    <td class="span1"> 
     <span data-bind="visible: $index() == 0,text:title"> </span> 
    </td> 
    <td class="span1 protected"> 
     <span data-bind="editable:$data[field],editableOptions: { mode: 'popup', pk: ID, url: '/create/EditInPlace'}"></span> 
    </td> 
    <!-- /ko --> 

사용법 :

<tr data-bind="templateWithContext: { name: 'textBoxTemplate', data: fundClasses, context: { title: 'Index', field:'INDEX_ID' }}"></tr> 

바인딩 핸들러 :

ko.bindingHandlers.templateWithContext = { 
    init: ko.bindingHandlers.template.init, 
    update: function (element, valueAccessor, allBindings, data, context) { 
     var options = ko.utils.unwrapObservable(valueAccessor()); 

     ko.utils.extend(context, options.context); 

     return ko.bindingHandlers.template.update.apply(this, arguments); 
    } 
};