无法识别阵列的Knockout绑定

时间:2016-10-24 16:51:13

标签: javascript jquery knockout.js

我遇到的问题是我的淘汰赛未被html识别:

<div class="row-fluid">
    <div class="span6">
        <div class="control-group">
            <fieldset>
                <legend>Rates</legend>
                <div id="creditcards-rates" class="row-fluid">
                    <p data-bind="visible: rates() == undefined || rates().length == 0">
                        No rates added yet.
                    </p>
                    <table data-bind="visible: rates() !== undefined && rates().length > 0" class="table table-striped table-condensed">
                        <thead>
                            <tr>
                                <th>Payment Status</th>
                                <th>Income Amount</th>
                                <th>Confirmed by Provider</th>
                                <th>Payment Status</th>
                                <th>Notes</th>
                                <th></th>
                            </tr>
                        </thead>
                        <tbody data-bind="foreach: rates">
                        <tr>

                            <td>
                                <input type="hidden" data-bind="value: Id, attr: { id: 'Rates[' + $index() + '].Id', name: 'Rates[' + $index() + '].Id' }" />
                            </td>
                            <td>
                                <a id="btn-remove" data-bind="click: $root.removeRate"><i class="icon icon-minus"></i></a>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    <button class="btn" data-bind="click: addNewRate"><i class="icon icon-plus"></i> Add New Payment</button>
                </div>
            </fieldset>
        </div>
    </div>
</div>

问题是数据绑定无法识别值。我在控制台中收到错误:

  

错误:语法错误,无法识别的表达式:input [data-bind ='value:   Id,attr:{id:'Rates ['+ $ index()+'] .Id',name:'Rates ['+   $ index()+'] .Id'}']

     

...);返回a},bc.error = function(a){throw new Error(“语法错误,   无法识别的exp ...

我的淘汰赛是:

var Micki = Micki || {};

Micki.Electro = {

    Edit: function (options) {

        var settings = $.extend({
            id: 0
        }, options);

        var _alerts;
        var _rates;
        var vm;

        function init(alerts, rates) {

            _alerts = alerts;
            _rates = rates;
            vm = new ViewModel();
            ko.applyBindings(vm);

            function ViewModel(options) {
                var self = this;

                self.mediator = null;
                self.publishKey = options.publishKey;
                self.rates = ko.observableArray([]);

                self.init = function (mediator, alerts, rates) {
                    self.mediator = mediator;
                    self.alerts = alerts;

                    //Rates.
                    $.each(rates, function (index, rate) {

                        var _rate = {
                            Id: ko.observable(rate.Id),
                            PaymentType: ko.observable(rate.PaymentType),
                            IncomeAmount: ko.observable(rate.IncomeAmount),
                            ConfirmedDate: ko.observable(rate.ConfirmedDate),
                            PaymentStatus: ko.observable(rate.PaymentStatus),
                            Note: ko.observable(rate.Note)
                        };

                        self.rates.push(_rate);
                    });

                    self.container.on("change keypress paste focus textInput input", function () {
                        self.mediator.publish(self.publishKey);
                    });
                };

                self.initFields = function () {
                    self.fields = [];
                    _.each($("[name^='Rates']"), function (field) {
                        self.fields.push(new Crate.Core.Field($(field), self.mediator, self.publishKey));
                    });

                    //_ratesAndTiers.initFields();
                    //_campaignSpecific.initFields();
                };

                self.addNewRate = function (data, event) {
                    alert("test");
                };

                return self;
            }
        }
    }
}

0 个答案:

没有答案