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" }
    }
});

MVVM js ファイルに var ddl を追加しました

 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 に答える