我看到一个很奇怪的问题。 我正在使用ko-js在jQuery移动应用程序中对某些表单域进行数据绑定。 我已成功使用selects和flipswitch绑定了所有其他字段,但是input type =“ text元素未将viewText的必填字段上的inputText绑定。如果我绑定到viewmodel中的另一个字段,它将正确显示/更新。

所以如果与

<input type="text" data-bind="textInput: controlData, attr:{'id': ftId()}" >

输入中没有任何值,但是如果我绑定

<input type="text" data-bind="textInput: label, attr:{'id': ftId()}" >

它完美地工作

更完整的HTML摘录:

<div data-role="content" data-theme="a">
  <div id="container">
    <div data-bind="foreach: formFields">
      <div data-role="fieldcontain" data-bind="visible: isFieldText()">
        <label data-bind="for: ftId(), text: label()"></label>
        <input type="text" data-bind="textInput: controlData, attr:{'id': ftId()}" >                                          
      </div>
      <div data-role="fieldcontain" data-bind="visible: isFieldCheckbox()">
        <label data-bind="for: cbId(), text: label()"></label>
        <input type="checkbox" data-role="flipswitch" data-bind="attr: {'id': cbId(), 'data-on-text': dataOnText(), 'data-off-text': dataOffText()}, checked:controlData" /> <!--data-wrapper-class="custom-size-flipswitch"-->        
      </div>            
      <div data-role="fieldcontain" data-bind="visible: isFieldSelect()">
        <label data-bind="for: selectId(), text: label()"></label>
        <select data-bind="attr: {'id': selectId()}, options: options, value: controlData"></select>
      </div>
    </div>
  </div>
    </div>

Viewmodel和applyBindings代码

var formFieldViewModel = function (data, target, parent) {
var _this = this;
this.isFieldText = ko.computed(function() {
return _this.controlType() === "text" ? true : false;
});
this.isFieldCheckbox = ko.computed(function() {
return _this.controlType() === "checkbox" ? true : false;
});
this.isFieldSelect = ko.computed(function() {
return _this.controlType() === "select" ? true : false;
});
this.ftId = ko.computed(function() {
return 'ft_'+_this.index();
});
this.cbId = ko.computed(function() {
return 'cb_'+_this.index();
});
this.selectId = ko.computed(function() {
return 'select_'+_this.index();
});
//-- Call mapping function --//
ko.mapping.fromJS(data, target, this);
};

这是JSON对象-JSON在JSONlint上进行验证

{"formFields":[{"index":0,"label":"experiment description","controlData":"dummy","controlType":"text","dataOffText":"","dataOnText":"","options":[]},{"index":1,"label":"odd S1 Label","controlData":"scottish","controlType":"text","dataOffText":"","dataOnText":"","options":[]},{"index":2,"label":"even S1 Label","controlData":"english","controlType":"text","dataOffText":"","dataOnText":"","options":[]},{"index":3,"label":"use 3P classic","controlData":false,"controlType":"checkbox","dataOffText":"no","dataOnText":"yes","options":[]},{"index":4,"label":"subject","controlData":"National identity","controlType":"select","dataOffText":"","dataOnText":"","options":["Sexuality","Religion","Race \u0026 Culture","National identity","Immigrant culture - football","Gender"]},{"index":5,"label":"country","controlData":"United Kingdom","controlType":"select","dataOffText":"","dataOnText":"","options":["Afghanistan","Albania","Algeria","American Samoa","Andorra","Angola","Anguilla","Antarctica","Antigua and Barbuda","Argentina","Armenia","Aruba","Australia","Austria","Azerbaijan","Bahamas","Bahrain","Bangladesh","Barbados","Belarus","Belgium","Belize","Benin","Bermuda","Bhutan","Bolivia","Bosnia and Herzegovina","Botswana","Bouvet Island","Brazil","British Indian Ocean Territory","Brunei Darussalam","Bulgaria","Burkina Faso","Burundi","Cambodia","Cameroon","Canada","Cape Verde","Cayman Islands","Central African Republic","Chad","Chile","China","Christmas Island","Cocos (Keeling) Islands","Colombia","Comoros","Congo","Congo, the Democratic Republic of the","Cook Islands","Costa Rica","Cote D\u0027Ivoire","Croatia","Cuba","Cyprus","Czech Republic","Denmark","Djibouti","Dominica","Dominican Republic","Ecuador","Egypt","El Salvador","Equatorial Guinea","Eritrea","Estonia","Ethiopia","Falkland Islands (Malvinas)","Faroe Islands","Fiji","Finland","France","French Guiana","French Polynesia","French Southern Territories","Gabon","Gambia","Georgia","Germany","Ghana","Gibraltar","Greece","Greenland","Grenada","Guadeloupe","Guam","Guatemala","Guinea","Guinea-Bissau","Guyana","Haiti","Heard Island and Mcdonald Islands","Holy See (Vatican City State)","Honduras","Hong Kong","Hungary","Iceland","India","Indonesia","Iran, Islamic Republic of","Iraq","Ireland","Israel","Italy","Jamaica","Japan","Jordan","Kazakhstan","Kenya","Kiribati","Korea, Democratic People\u0027s Republic of","Korea, Republic of","Kuwait","Kyrgyzstan","Lao People\u0027s Democratic Republic","Latvia","Lebanon","Lesotho","Liberia","Libyan Arab Jamahiriya","Liechtenstein","Lithuania","Luxembourg","Macao","Macedonia, the Former Yugoslav Republic of","Madagascar","Malawi","Malaysia","Maldives","Mali","Malta","Marshall Islands","Martinique","Mauritania","Mauritius","Mayotte","Mexico","Micronesia, Federated States of","Moldova, Republic of","Monaco","Mongolia","Montserrat","Morocco","Mozambique","Myanmar","Namibia","Nauru","Nepal","Netherlands","Netherlands Antilles","New Caledonia","New Zealand","Nicaragua","Niger","Nigeria","Niue","Norfolk Island","Northern Mariana Islands","Norway","Oman","Pakistan","Palau","Palestinian Territory, Occupied","Panama","Papua New Guinea","Paraguay","Peru","Philippines","Pitcairn","Poland","Portugal","Puerto Rico","Qatar","Reunion","Romania","Russian Federation","Rwanda","Saint Helena","Saint Kitts and Nevis","Saint Lucia","Saint Pierre and Miquelon","Saint Vincent and the Grenadines","Samoa","San Marino","Sao Tome and Principe","Saudi Arabia","Senegal","Serbia and Montenegro","Seychelles","Sierra Leone","Singapore","Slovakia","Slovenia","Solomon Islands","Somalia","South Africa","South Georgia and the South Sandwich Islands","Spain","Sri Lanka","Sudan","Suriname","Svalbard and Jan Mayen","Swaziland","Sweden","Switzerland","Syrian Arab Republic","Taiwan, Province of China","Tajikistan","Tanzania, United Republic of","Thailand","Timor-Leste","Togo","Tokelau","Tonga","Trinidad and Tobago","Tunisia","Turkey","Turkmenistan","Turks and Caicos Islands","Tuvalu","Uganda","Ukraine","United Arab Emirates","United Kingdom","United States","United States Minor Outlying Islands","Uruguay","Uzbekistan","Vanuatu","Venezuela","Viet Nam","Virgin Islands, British","Virgin Islands, U.s.","Wallis and Futuna","Western Sahara","Yemen","Zambia","Zimbabwe"]},{"index":6,"label":"language","controlData":"English","controlType":"select","dataOffText":"","dataOnText":"","options":["Afrikaans","Albanian","Arabic","Armenian","Basque","Bengali","Bulgarian","Catalan","Cambodian","Chinese (Mandarin)","Croation","Czech","Danish","Dutch","English","Estonian","Fiji","Finnish","French","Georgian","German","Greek","Gujarati","Hebrew","Hindi","Hungarian","Icelandic","Indonesian","Irish","Italian","Japanese","Javanese","Korean","Latin","Latvian","Lithuanian","Macedonian","Malay","Malayalam","Maltese","Maori","Marathi","Mongolian","Nepali","Norwegian","Persian","Polish","Portuguese","Punjabi","Quechua","Romanian","Russian","Samoan","Serbian","Slovak","Slovenian","Spanish","Swahili","Swedish","Tamil","Tatar","Telugu","Thai","Tibetan","Tonga","Turkish","Ukranian","Urdu","Uzbek","Vietnamese","Welsh","Xhosa"]},{"index":7,"label":"location","controlData":"Southampton","controlType":"select","dataOffText":"","dataOnText":"","options":["Cardiff","Bournemouth","Upsalla","Rotterdam","Madrid","Southampton","Trondheim","Port Elizabeth","Cape Town","Helsinki","Pisa","Wroclaw","Palermo","Budapest","Malaga","Magaluth","Caerdydd","Glamorgan","Granada","Geneva","Berlin"]}]}

  ask by mhall translate from so

本文未有回复,本站智能推荐:

1回复

剔除foreach数据绑定到分组数据

我试图找出如何使用敲除foreach数据绑定遍历.Net分组。 我遇到的问题是,一旦将IGroupings序列化为JSON,我不知道如何对其进行迭代。 在服务器端,我有一个.Net对象,看起来像这样: 我通过按其StartDate对BookingLeg实体的集合进行分组来创建Group
1回复

选中列表视图中的JSON数据复选框

KO绑定正在工作,并且我在IsAnswer分配true和false,但是list view有时未显示该复选框。 如何在不失去风格的情况下完成?
1回复

数据绑定到选择

我有一个jQuery函数从服务获取所有团队。 我如何将其数据绑定到选择框?
1回复

jQuerymobile使用Knockout.js数据绑定时无法正常工作

我通过jquery mobile编写了一个链接,例如:<a href =“#detail” /> 它第一次工作。 然后我使用ko bind修改它,例如:<a href =“#detail” data-bind =“ click:newAdvice”> 它不能更
1回复

如何从淘汰赛数据绑定中获取我的JQuery复选框显示值?

我在使用Knockout绑定绑定JQuery Mobile复选框时遇到问题。 我在表单其他部分上的所有文本框均正常工作,并且如该图所示,布尔值设置为true(“加入奖励和输入竞赛”的值)。 我已经了解到,Knockout和JQuery处理事件的方式之间存在一些问题,因此我怀疑我的问题与此有
1回复

jQueryMobilePopup和ListView,以及Popupdiv内部的Knockout.js数据绑定-不起作用

我正在使用jQuery Mobile和kickout.js在移动网站上工作。 我在jQuery Mobile的弹出窗口和listview中有一个(复杂的)场景,在弹出窗口div内有敲除数据绑定,但是我无法使其正常工作。 我有一个嵌套的警报列表,如下所示。 对于每一天,它都会创建一个列表分
1回复

使用基因敲除.js和jQueryMobile进行复选框数据绑定

我面临使用基因敲除js的数据绑定复选框的问题。 jsfiddle http://jsfiddle.net/sajesh1985/ypbLN/ (HTML)代码: <h2>View1</h2><h4>Select Columns:</h4>&l
4回复

Knockout和jQueryMobile:将数据绑定到选择列表

我在同一个项目中使用了Knockout(版本2.0)和jQuery Mobile(版本1.0.1)。 问题在于将数据绑定到选择列表。 jQuery Mobile以一种看似选择的值和实际列表是单独元素的方式呈现选择列表。 这是通过执行来解决的 更改列表或选定值后。 根据我的经验,这是一