替换单引号AngularJS工厂

时间:2015-03-24 18:51:51

标签: javascript json angularjs

我想使用.replace("'", r"\'")方法来避免JSON字符串中单引号引起的问题..以便我的工厂按预期工作

我可以从This post找到的最简单的解决方案建议使用replace方法,然而,在JS中出现新问题,我在工厂内实施它时遇到了麻烦。

我不太确定在何处以及如何设置它,以便任何给定的控制器调用不同的函数(尤其是下面脚本末尾的getDishesgetDish函数)都得到一个& #34;格式化字符串"

工厂:

angular.module('wmapp.factory_dishes', [])

.factory('dishesFactory', function (){
var factory = {
    dishes :[
        {   nameEnglish: 'beef burgungdy', 
            nameLocal: 'boeuf bourgignon',
            description: 'xxxxxx',
            region: 'sicile',
            itemid: 'IT018',
            cuisineTypeIsoCode: 'IT',
            country:'France',
            dishCategory: 'Meat',

        },
        {   nameEnglish: 'duck liver', 
            nameLocal: 'foie gras',
            description: 'xxxxxx',
            region: 'sicile',
            itemid: 'IT021',
            cuisineTypeIsoCode: 'IT',
            country:'France',
            dishCategory: 'fruit',

        },  
        {   nameEnglish: 'veal stew',
            nameLocal: 'blanquette de veau',
            description: 'xxxxxx',  
            region: 'parme',
            itemid: 'IT023',
            cuisineTypeIsoCode: 'IT',
            country:'France',
            dishCategory: 'fruit',

        },
        {   nameEnglish: 'onion soup', 
            nameLocal: 'soxxxxxx',
            region: 'vanitia',
            itemid: 'IT022',
            cuisineTypeIsoCode: 'IT',
            imageSource: '( "img/" + dish.cuisineTypeIsoCode + "/" + dish.itemid + "small.jpg")',
            country:'France',
            dishCategory: 'Soup',
        },

        {  nameEnglish: 'TAPENADE',
           nameLocal: 'Tapenade', 
           description: 'xxxxxx',
           region: 'Provence-Alpes-Côte d'Azur', 
           regioncode: 'FR.B8', 
           itemid: 'FR002', 
           cuisineTypeIsoCode: 'FR', 
           dishCategory: 'Entrée / Appetizers', 
           country: 'France'}




      ], 
      getDishes : function (){
        return factory.dishes;
      },
      getDish :function (itemid){
        var dish = {};
        angular.forEach(factory.dishes, function(value, key) {
            if (value.itemid == itemid){
                dish = value
            }
        });       

        return dish;
      }
}
return factory;

})

0 个答案:

没有答案
相关问题