0

我是使用 Knockout 进行数据绑定和 MVC 的新手,我可以很好地检索在 Json 对象中返回的数据,但是当我尝试返回用户数据并且保存我的值的选择为空时。如果我分离删除 saveContent div 并将保存按钮控件放在 searchAudio div 中,则返回用户输入数据,但我需要返回用户选择和输入的所有表单数据。

<form action="AudioLookup" method="get" enctype="multipart/form-data">
   <div id="saveContent" data-bind="with: saveContent">
    <div id="allAudio" data-bind="with: $root.allAudio">
        <h3>Audio Playback</h3>
            <table>
                <thead>
                        <tr>
                            <th>Bind Audio</th>
                            <th>ID</th>
                            <th>Text</th>
                            <th>Url</th>
                            <th>File Name</th>
                            <th>Prompt Type</th>
                        </tr>
                </thead>
                <tbody data-bind="foreach: AudioResults">
                    <tr>
                        <td><input  type="radio" name="adgroup"/></td>
                        <td data-bind="text : _id"></td>
                          <td ><a href="http://customaudio.showings.com/"data-bind="text : Text"></a></td>
                          <td data-bind="text: aUrl"></td>
                          <td data-bind="text: fileName"></td>
                          <td data-bind="text: PromptType"></td>
                    </tr>
                </tbody>         
            </table>
         <button data-bind="click: getAllAudio">Get Audio</button>   
    </div>
    <br /> 
    <hr />
    <div id="searchAudio" data-bind="with: $root.searchAudio">
     <h3>Refine Audio Lookup</h3>
        <label for="CallCenterDLL">Choice Call Center: </label>
             <select id="CallCenterDLL" data-bind ="value: searchfields.CCCode" name="CallCenterT">
                <option value =""></option>
                <option value = "11">Kansas City</option>
                <option value = "6">Dallas</option>
                <option value = "7">Houston</option>
                <option value = "8">SanAntonio</option>
                <option value = "12">Charlotte</option>
                <option value = "9">Raleigh</option>
             </select>
        <div>
            <label for="RBgroup">Choice Prompt Type: </label>
            <br/>
            <input type="radio" name="RBgroup" value='3' data-bind ="checked: searchfields.searchType"/> Agent<br/>
            <input type="radio" name="RBgroup" value='4' data-bind ="checked: searchfields.searchType"/>Office<br/>
        </div> 
        <input type="text" name="serchTxt" placeholder="search string Here" data-bind="value: searchfields.searchVal" onblur="minleng(this.value,25);Minimum(this,3);" onkeypress="minleng(this.value,25)"  />
        <button data-bind="click: runQuery">Search Data</button>
           @* <div id="select-all" data-bind="with: $root.select-all"> *@
            <table>
                <thead>
                    <tr>
                        <th>
                        <input type="checkbox" name="select-all" id="select-all"/>Select All
                        </th>
                    </tr>
                </thead>
                <tbody data-bind="foreach: dataResult">  
                    <tr>
                        <td><input data-bind="value: PK" class="selectedPK" type="checkbox" /></td>
                        <td data-bind="text: PKType"></td>
                        <td data-bind="text: DisplayVal"></td>
                    </tr>
                </tbody>
            </table>
            @*</div>*@  
     </div>
 <button data-bind="click: SaveQuery">Save Data</button>
  </div>
 </form> 


function saveViewModel() {
        var self = this;
        var SviewModel = function (CCCode, PK, PKType, SearchType, SearchVal, Text, fileName, aUrl) {
            self.searchfields.CCCode = ko.observable(CCCode);
            self.searchfields.searchType = ko.observable(SearchType);
            self.searchfields.searchVal = ko.observable(SearchVal);
            self.PK = ko.observable(PK);
            self.PKType = ko.observable(PKType);
            self.Text = ko.observable(Text);
            self.fileName = ko.observable(fileName);
            self.aUrl = ko.observable(aUrl);

        }

        self.state = ko.observable();
        self.dataResult = ko.observableArray();
        self.SaveQuery = function () {
            alert(ko.toJSON(SviewModel));
            $.ajax(
        {
            url: "/CallCenter/SaveQuery",
            contentType: "application/json",
            type: "POST",
            dataType: "json",
            data: ko.toJSON(self.dataResult),
            success: function (data) {
                self.SaveResult(data);
            }
        });
        }
    }
4

1 回答 1

0

你提醒:-

alert(ko.toJSON(SviewModel));

您发送的数据:-

data: ko.toJSON(self.dataResult),

那就是 :-

self.dataResult = ko.observableArray();

这似乎未使用....所以一切都为空也不足为奇

于 2012-06-10T21:46:01.107 回答