1

我有一个基本的剑道视图,我想知道是否有一种方法可以访问 view.params 而不使用 data-show 或 data-init 来运行 js 或者如果我确实在 data-show 上使用当前 functon 调用我怎么能动态填充我的 EDIT 按钮的数据元素?

<!-- eventDetail view -------------------------------------------------------------------------------------------------->
<div data-role="view" id="view-eventDetail" data-show="getEventDetailData" data-title="eventDetail">
    <header data-role="header">
        <div data-role="navbar">
            <span data-role="view-title"></span>
            <a data-align="left" data-role="button" class="nav-button" href="#view-myEvents">Back</a>
            <a data-align="right" data-role="button" class="nav-button" data-click="showEventUpdate" data-event_id="view.params.event_id" data-user_id="view.params.user_id">Edit</a>
        </div>
    </header>

    <div id="eventDetail"></div>
</div>
4

1 回答 1

10

到目前为止我发现的最好的方法(在视图中访问视图参数)是使用 Kendo ViewModel 方法 - MVVM - 和模板 - 从查询字符串中拉入 view.params 点击:

 <a data-role="button" href="#view-Home?userID=2&userType=1&trainerID=2"> 

然后通过视图的 data-show 或 data-init 方法调用脚本并绑定 viewModel:

<!-- =========================================================================================== Home page -->
    <div data-role="view" id="view-Home" data-title="Home" data-show="checkAuth" data-model="home_viewModel" >

        <div id="homeWrapper">

            <div id="myTrainerInfo" data-template="myTrainerIcon-template" data-bind="source: user_info" ></div>

    </div>


    <!-- ========================================================================================= Home script -->
    <script>

            //init the viewmodel            
            var home_viewModel = kendo.observable({
                user_info: []

            });


        function checkAuth(e) {
            var userID = e.view.params.userID;
            var userType = e.view.params.userType;
            var trainerID = e.view.params.trainerID;

            var userData = {userID:userID,userType:userType,trainerID:trainerID};


            //set the viewmodel data
            home_viewModel.set("user_info", userData);


        }           

    </script>

然后可以通过 ${var_name} 或 HTML data-bind="value: var_name" 访问变量:

        <!-- ============================================================================== myTrainerIcon template -->
    <script id="myTrainerIcon-template" type="text/x-kendo-template">

        <div id="myTrainerIcon" class="homePageIcons">
            <a data-role="button" href="\\#view-trainerDetail?user_id=${userID}&amp;trainer_id=${trainerID}">
                <img src = "styles/icons/myTrainerICON.png" alt="myTrainer" />
            </a>
            <div class = "icon-text" >myTrainer</div>
        </div>
<div>TrainerID: <input name="edit_id" id="edit_id" data-min="true" class="k-input" data-bind="value:     trainerID" type="text" /></div>
    </script>

我确信有一种不同的方法可以做到这一点,但到目前为止我自己还没有发现任何东西..

于 2013-02-16T18:06:55.233 回答