1

我一直在尝试使用 durandal 框架,必须说我很高兴。我正在使用http://stephenwalther.com/的电影教程并进行了一些更改。在 Ryan Keeters Youtube 视频的帮助下。我已经完成了使用模态编辑电影。

但是我无法通过模态添加新电影。

我已经创建了一个 add.html 和 add.js,但是当单击用于创建新电影的链接并且模式显示它显示我在中间的页面时(当我进一步单击时就像一个循环)。

这是我对 show.html 的绑定:

<a data-bind="click: viewAddMovieModal">Add Movie</a>

这是javascript:

define(function (require) {
    var self = this;

    var vm = {
        activate: activate,
        title: 'movies page',
        movies: ko.observableArray([])
    };
    //return vm;

   // self.moviesRepository = require("repositories/moviesRepository");
    self.router = require('durandal/plugins/router');
    self.system = require('durandal/system');
    self.app = require('durandal/app');
    self.movie = require('viewmodels/movie');
    self.addmovie = require('viewmodels/add');
    //self.Movies = ko.observableArray([]);
    self.viewMovieModal = function (movie, element) {
        self.app.showModal(movie).then(function (result) {
            if (result) {
                //self.app.showMessage(result.toString(), result.toString());
               vm.movies.remove(movie);
            }
        }).fail(function (result) {
            self.app.showMessage(result.toString(), "Something went wrong!");
        });
    };

    self.viewAddMovieModal = function (addmovie,element) {
      //  self.app.showModal(addmovie).then(function (result) {
         //   self.app.showMessage(result.toString(), result.toString());
      //  });
        self.app.showModal(null, element, addmovie);
    };

    init();

    function init() {
        vm.movies.push(new movie("Star wars", "Piet"));
        vm.movies.push(new movie("Harry Potter", "Jan"));
        vm.movies.push(new movie("Hangover", "Klaas"));
    }

    function activate() {
        self.system.log("I get in the activate function!");
    }

    return {
        activate: activate,
        movie: movie,
        addmovie:addmovie,
        vm:vm,
        viewMovieModal: viewMovieModal
    };
});
4

0 回答 0