1

又是下一个问题,这次是一个棘手的问题,

数据源:

var dsCountryList =
       new kendo.data.DataSource({
           transport: {
               read: {
                   dataType: "jsonp",
                   url: "/Masters/GetCountries"
               }
           },
           schema: {
               model: {
                   id: "CountryID",
                   fields: {
                       "CountryDesc": {

                       }
                   }
               }
           }
       });

可观察对象

function Set_MVVMSupplier() {
    vmSupplier = kendo.observable({
        SupplierID: 0,
        SupplierName: "",
        AccountNo: "",
        CountryList: dsCountryList,
});

    kendo.bind($("#supplierForm"), vmSupplier);
}

这是绑定到可观察对象的 html,但我没有填充组合框,每次我单击组合请求时都会转到服务器并为 countryID、CountryDesc 带来 json 格式的数据

 <div class="span6">
                <div class="control-group">
                    <label class="control-label" for="txtCountryId">Country</label>
                    <div class="row-fluid  controls">
                        @*<input class="input-large" type="text" id="txtCountryId" placeholder="CountryId" data-bind="value: CountryId">*@
                        <select  id="txtCountryId" data-role="dropdownlist"
                             data-text-field="CountryDesc" data-value-field="CountryID" , data-skip="true"
                             data-bind="source: CountryList, value: CountryDesc">
                        </select>
                    </div>
                </div>
            </div>
4

1 回答 1

2

我没有得到答案,所以我找到了代码的替代工作冰。看看,如果有帮助,请投票。

在 js 文件中为 ddl 创建模型

 ddl = kendo.data.Model.define({
    fields: {
        CountryId: { type: "int" },
        ConfigurationID: { type: "int" }
    }
});

将 var ddl 添加到 MVVM js 文件

 vmSupplier = kendo.observable({
    CountryId: new ddl({ CountryId: 0 }),
    ConfigurationID: new ddl({ ConfigurationID: 0 }),});

在控制器中添加代码

 using (CountriesManager objCountriesManager = new CountriesManager())
        {
            ViewBag.Countries = new SelectList(
                objCountriesManager.GetCountries().Select(p => new { p.CountryID, p.CountryDesc })
                , "CountryID", "CountryDesc"); ;
        }

在cshtml中添加代码

      <div class="span4">
                        <label class="control-label" for="txtCountryId">Country</label>
                        @Html.DropDownList("Countries", null,
                      new System.Collections.Generic.Dictionary<string, object> {
                      {"id", "txtCountryId" },
                      { "data-bind","value: CountryId"} })

                    </div>

这样我就解决了问题

于 2013-09-17T07:48:37.523 回答