1

我尝试使用knockoutjs模板绑定来动态绑定包含一组单选按钮的字段集。这里我的问题是移动单选按钮 css 不适用单选按钮。我在stackoverflow中搜索了按钮问题,但没有找到单选按钮。所以你能帮我找到解决方案吗

<script type="text/x-jquery-tmpl" id="MobileQuestionTemplate"> 
     <div data-role="fieldcontain"> 
        <div class="divborder">  
            <label id="l2" for="select-choice-1" class="questiontext"  data-bind="text:                          QuestionText"></label> 
            <br />    
            <fieldset data-role="controlgroup" data-mini="true"  align="center" data-       bind="attr: { visible: QuestionType==13,id:QuestionID+'_fld'},template: {name:'MobileOptionTemplate', foreach: OptionList}"></fieldset>  
        </div>  
    </div>
</script>
<script type="text/x-jquery-tmpl" id="MobileOptionTemplate"> 
    <input type="radio" data-bind="attr: {id:QuestionID+'_'+OptionID+'_rbt',val:OptionID,name: QuestionID+'_selectedObjects'}"/>
    <label data-bind="text: OptionText ,attr: { for: QuestionID+'_'+OptionID+'_rbt'}" /> 
</script>
<table id="tblMobileMgrQuestions" data-bind="template: {name:'MobileQuestionTemplate', foreach: MobileManagerviewmodel.ManagerQuestions}">
</table>

你能告诉我我需要在哪里更改代码js才能申请吗css

$.ajax(
{
    url: "/Render/LoadSurveyManagerQuestions?surveyGuid=" + surveyGuid + "&surveyItemGuid=" + rsg,
    success: function (result) 
    {
        ko.bindingHandlers['button'] = 
        {
            init: function (element, valueAccessor) 
            {
                debugger;
                $(element).button(ko.utils.unwrapObservable(valueAccessor()));
            }
        }
        debugger;
        var SurveyManagerQuestion = function (managerQuestions) 
        {
            var Self = this;
            Self.ManagerQuestions = ko.observableArray(managerQuestions);

            Self.AssignQuestionAnswer = function (option) 
            {
                ko.utils.arrayFirst(Self.ManagerQuestions(), function (question) 
                {
                    if (question.QuestionID == option.QuestionID) 
                    {
                        question.OptionId = option.OptionID;
                        question.OptionText = option.OptionText;
                    }
                });
            };

            Self.Save = function () 
            {
                alert('hi');
            };
        };
        debugger;
        MobileManagerviewmodel = new SurveyManagerQuestion(result);
        ko.applyBindings(MobileManagerviewmodel, document.getElementById("tblMobileMgrQuestions"));
    }
});

感谢您提前提供任何帮助。

4

1 回答 1

1

要动态增强单选按钮的标记,请使用以下内容。

$('input[type=radio]').checkboxradio().trigger('create')
于 2013-04-15T07:31:31.210 回答