【问题标题】:mobile css for radio button not applying in knock template binding单选按钮的移动 CSS 不适用于敲击模板绑定
【发布时间】:2013-04-05 21:54:18
【问题描述】:

我尝试使用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"));
    }
});

提前感谢您的帮助。

【问题讨论】:

  • 在动态附加它们之后使用$('input[type=radio]').checkboxradio('refresh')
  • 当我使用上述刷新方法时,我收到此错误“未捕获的无法在初始化之前调用 checkboxradio 上的方法;尝试调用方法‘刷新’”
  • 好的,那就试试这个$('input[type=radio]').checkboxradio().trigger('create')
  • 好的,非常感谢,我的问题解决了
  • 添加这个/ $( '.selector' ).controlgroup().trigger('create');

标签: jquery-mobile knockout-mapping-plugin


【解决方案1】:

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

$('input[type=radio]').checkboxradio().trigger('create')

【讨论】:

  • @user1622436 你用字段集包裹它们了吗? &lt;fieldset data-role="controlgroup" data-type="horizontal" &gt;
  • 是的,我这样写
猜你喜欢
  • 1970-01-01
  • 2019-01-08
  • 1970-01-01
  • 2015-07-30
  • 1970-01-01
  • 1970-01-01
  • 2012-09-11
  • 2017-10-03
  • 1970-01-01
相关资源
最近更新 更多